HighChart自定义菜单,当我向下钻取和钻取自定义事件(上下文菜单)不起作用时



我正在使用highchart上下文菜单(使用:https://blacklabel.github.io/custom_events/js/customEvents.js(并向下钻取和向上钻取。

问题:

当我右键单击饼图时,我们可以调用上下文菜单中的警报。同时,当我向下钻取并向上钻取然后右键单击饼图时,上下文菜单不起作用。在情节选项中它工作正常,但我在绘图选项中不需要它。

法典:

chart: {
type: 'pie',
events: {
drillup: function () {
var chart = this;
window['chart'] = chart;
setTimeout(function () {
console.log('drillup',chart.series[0].events);
if (!chart.plotOptions){
chart.plotOptions = {};
}
if (!chart.plotOptions.series) {
chart.plotOptions.series = {};
}
if (!chart.plotOptions.series.events) {
chart.plotOptions.series['events'] = {                   
contextmenu: function () {
alert('hi33')
}
}
}
/*
plotOptions: {
series: {
events: {                   
contextmenu: function () {
alert('hi33')
}
},
}
},
*/
console.log('drillup222',chart);
}, 100);
},
drilldown: function (e) {
var chart = this;
window['chart'] = chart;
setTimeout(function () {
if (!chart.series[0].events) {
chart.series[0]['events'] = {                   
contextmenu: function () {
alert('hi33')
}
}
}
console.log('drilldown',chart.series[0]);
}, 100);
}
}
},

https://jsfiddle.net/k14ajzpo/2/https://jsfiddle.net/0txqk2cn/1/

此问题的解决方法是将事件添加到 plotOptions 并检查主系列上是否发生了事件。检查下面发布的演示和代码。

法典:

chart: {
type: 'pie',
events: {
load: function () {
var chart = this;
chart.series[0].customEventsEnabled = true;
}
}
},
plotOptions: {
series: {
events: {
contextmenu: function() {
var series = this;
if (series.customEventsEnabled || series.drilldownLevel) {
console.log('working');
}
}
}
}
}

演示:

  • https://jsfiddle.net/BlackLabel/0pLqvmky/

最新更新