海图森伯斯特海图

时间:2018-10-16 14:11:10

标签: javascript highcharts

我正试图在森伯斯特图表上捕获追溯事件,但我无法实现。

我将事件对象添加到了图表对象,但仍然无法在函数内触发警报。

我基本上希望在向下钻取一个或多个级别之后单击右上角的按钮时,在我们向上钻取时触发alert / console.log。

codepen在这里供您参考。

    Highcharts.chart('container', {

      chart: {
        height: '100%',
        events: {
          drillup: function() {
            alert('Drilling up')
          }
        }
      },

      title: {
        text: 'World population 2017'
      },
      subtitle: {
        text: 'Source <href="https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)">Wikipedia</a>'
      },
      series: [{
        type: "sunburst",
        data: data,
        allowDrillToNode: true,
        cursor: 'pointer',
        dataLabels: {
          format: '{point.name}',
          filter: {
            property: 'innerArcLength',
            operator: '>',
            value: 16
          }
        },
        levels: [{
          level: 1,
          levelIsConstant: false,
          dataLabels: {
            filter: {
              property: 'outerArcLength',
              operator: '>',
              value: 64
            }
          }
        }, {
          level: 2,
          colorByPoint: true
        },
        {
          level: 3,
          colorVariation: {
            key: 'brightness',
            to: -0.5
          }
        }, {
          level: 4,
          colorVariation: {
            key: 'brightness',
            to: 0.5
          }
        }]

      }],
      tooltip: {
        headerFormat: "",
        pointFormat: 'The population of <b>{point.name}</b> is <b>{point.value}</b>'
      }
    });

请咨询。

1 个答案:

答案 0 :(得分:2)

您可以对sunburst.prototype.drillUp方法进行包装,并在进行向上钻取之前或之后添加代码。

(function(H) {  
  H.wrap(H.seriesTypes.sunburst.prototype, 'drillUp', function (proceed) {

    console.log("Before drillup.");

    proceed.apply(this, Array.prototype.slice.call(arguments, 1));

    console.log("After drillup.");

  });
})(Highcharts);

包装原型函数文档:
https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

在线演示:
https://jsfiddle.net/wchmiel/gsx1bacu/

相关问题