gpt4 book ai didi

Highcharts饼图获取所选饼图id

转载 作者:行者123 更新时间:2023-12-03 00:00:14 26 4
gpt4 key购买 nike

如何获取 Highcharts 饼图并获取所选饼图 id?

我有一个数据数组

var data= { name: series[i], y: Data[i],id:categorydata[i] };

渲染图表

new Highcharts.Chart({ ....

....
series: [{
type: 'pie',
name: 'Category',
data: data
}]
});

如何获取所选饼图的 ID。

我正在做这个

plotOptions: {
series: {
animation: false,
events:{
click: function (event) {
var point = this;
//How do I Access the id???????
alert('value: ' + this.series);


}
}
},

最佳答案

您希望在点配置上进行事件处理,而不是在系列上。每个楔形都是单个系列中的一个点:

   var data = [{ name: 'One', y: 10, id: 0 },{ name: 'Two', y: 10, id: 1 }];

// some other code here...

series:[
{
"data": data,
type: 'pie',
animation: false,
point:{
events:{
click: function (event) {
alert(this.x + " " + this.y);
}
}
}
}
],

fiddle here .

完整运行代码:

var chart;
point = null;
$(document).ready(function () {

var data = [{ name: 'One', y: 10, id: 0 },{ name: 'Two', y: 10, id: 1 }];

chart = new Highcharts.Chart(
{
series:[
{
"data": data,
type: 'pie',
animation: false,
point:{
events:{
click: function (event) {
alert(this.id);
}
}
}
}
],
"chart":{
"renderTo":"container"
},
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="width: 320px; height: 200px"></div>

关于Highcharts饼图获取所选饼图id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15533810/

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