问题描述
我需要访问getSelectedPoints
事件上的click
数组,但是有一个延迟,我得到了先前选择的点,现在我正在使用setTimeout
函数如下所示的代码,但这不是解决方案;因为我不能期望点选择何时完成。
我已经看到了这个问题
但它解决了 JQuery 和具有select
事件且在新版本的hightcharts中已弃用的 hightcharts 的旧版本中的问题。我需要答案在 javascript 和 hightcharts v8中。
plotOptions: {
series: {
events: {
click: function(event) {
var chart = new Highcharts.Chart(this.divelement.nativeElement,this.options);
chart.getSelectedPoints().forEach(point=>{
setTimeout(()=>{
// do something here
},500);
});
}
}
}
解决方法
您在哪里找到不推荐使用select
事件的信息?并非如此,该事件已得到完全支持-API:https://api.highcharts.com/highcharts/series.line.point.events.select
以及演示如何获取所选点的数组的演示:
https://jsfiddle.net/BlackLabel/uq4nrtky/
point: {
events: {
select: function() {
var selectedPoints = chart.getSelectedPoints()
selectedPoints.push(this);
console.log(selectedPoints)
}
}
}