我正在尝试在森伯斯特图表上捕获追溯事件,但我无法实现。
我将事件对象添加到了图表对象,但仍然无法在函数内触发警报。
我基本上希望在钻取一个或多个级别后单击右上方的按钮来向上钻取时触发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>'
}
});
请指教。
最佳答案
您可以对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/
关于javascript - 海图森伯斯特海图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52837499/