Highcharts - manually trigger hover event on a poi

2020-02-08 04:31发布

When you hover over a point in a Highcharts chart, you get a nice enlarged circle under you cursor (or other symbol). What I would like to do manually trigger that hover effect.

I know that I can manually trigger the mouseOver event on the point, but that doesn't give me the enlarged symbol on the chart that I am going for.

4条回答
一纸荒年 Trace。
2楼-- · 2020-02-08 04:43

I found the answer by looking at the source - call "setState('hover');" on the point that you want to be highlighted.

查看更多
姐就是有狂的资本
3楼-- · 2020-02-08 04:46

Just to add an important information:

For StockChart this solution doesn't work:

In this example you have to replace this:

chart.tooltip.refresh(chart.series[0].data[i]);

to this:

chart.tooltip.refresh([chart.series[0].points[i]]);

One possible solution is available here.

查看更多
够拽才男人
4楼-- · 2020-02-08 04:53

Here is an example of how to select (hover) the last valid point in series programmatically:

  // Find last not-null point in data
  let last = data.indexOf(null) - 1;
  last = (last === -2) ? data.length - 1 : last;
  const lastPoint = this.series[0].points[last];

  // Trigger the hover event 
  lastPoint.setState('hover');
  lastPoint.state = '';  // You need this to fix hover bug
  this.tooltip.refresh(lastPoint); // Show tooltip

Full JSFiddle exapmle

enter image description here

查看更多
萌系小妹纸
5楼-- · 2020-02-08 04:58

To give a more direct answer (e.g. for then you don't have access to the highcharts instance):

you need to create a mouseover event and give it proper pageX and pageY attributes before you trigger it.

查看更多
登录 后发表回答