【问题标题】:highchart custom menu with when i drilldown and drillup custom event (contextmenu) not working当我向下钻取和向上钻取自定义事件(上下文菜单)时,highchart 自定义菜单不起作用
【发布时间】:2019-09-06 13:14:45
【问题描述】:

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

问题:

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

代码:

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/

【问题讨论】:

  • 格式化的代码段,固定的语法/拼写

标签: highcharts drilldown custom-events


【解决方案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');
          }
        }
      }
    }
  }

演示:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多