Highcharts - 将鼠标悬停在列上的事件

Highcharts - mouseover event over column

提问人:Arvind 提问时间:9/7/2023 最后编辑:Arvind 更新时间:9/7/2023 访问量:31

问:

我们正在尝试访问用户悬停的列的值。

最初我们使用 Window.event 来捕获点,但在升级 angular 和 node 版本后,window.event 没有按预期响应(因为它已被弃用)。请让我知道阅读悬停列的任何替代方案。

技术栈: Angular 16(从版本 8 升级而来) 节点 16.16

请协助。

我们需要读取柱形图悬停柱的值。

plotOptions: {
series: {
    events: {
        mouseOver: ($events) => {
            // I would like to capture data on which mouse is hovering
            console.log($events);
        }
    }
}

}

Angular events highcharts 鼠标悬停

评论


答:

0赞 ppotaczek 9/7/2023 #1

首先,您需要使用:

  • plotOptions.series.point.events.mouseOver

而不是:

  • plotOptions.series.events.mouseOver

要获得悬停点,请使用:event.target

plotOptions: {
  series: {
    point: {
      events: {
        mouseOver: (event) => {
          console.log(event.target);
        }
      }
    }
  }
}

或在基本功能中:this

mouseOver: function (this: Highcharts.Point) {
  console.log(this);
}

现场演示:https://stackblitz.com/edit/highcharts-angular-line-zha7hq?file=src%2Fapp%2Fapp.component.ts

API 参考:https://api.highcharts.com/highcharts/plotOptions.column.point.events.mouseOver