当我创建一个 html 图例时,我想知道被单击的元素。 Hichgharts 似乎没有把它藏在任何地方。
这里是一些示例代码:
point:{
events:{
legendItemClick:function(event){
//how to get the element clicked here?
//want something to happen if it has a class of pieLegendNumber
以及创建图例的代码:
legend : {
enabled: true,
layout: 'vertical',
align: 'left',
useHTML: true,
verticalAlign: 'top',
labelFormatter: function() {
return '<div style="width:150px;"><span style="float:left;width: 230px;min-width: 230px;">'
+ this.name
+ '<span style="float:right;color:red" class="pieLegendNumber">'
+ this.y
+ '</span></div>';
}
},
title:{
text:"legend"
},
完整代码可以在 here 找到.
感谢您花时间阅读我的问题。
最佳答案
我使用数据点的index
属性来获取已单击的图例元素
http://jsfiddle.net/bgxa62z1/4/
希望这有帮助
[更新]
您可以使用event.browserEvent.target
,或者有时如果将处理程序添加到series.event.click,您可以使用event.originalEvent.target
来获取已被单击的元素。
关于javascript - Highcharts html 图例,点击了哪一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609508/