gpt4 book ai didi

javascript - Highcharts Sunburst 图表钻取

转载 作者:行者123 更新时间:2023-12-01 01:35:48 26 4
gpt4 key购买 nike

我试图捕获旭日图上的钻取事件,但无法实现。

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

我基本上希望在向下钻取一个/多个级别后,通过单击右上角的按钮进行向上钻取时触发警报/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);

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

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

关于javascript - Highcharts Sunburst 图表钻取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52837499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com