javascript - Highcharts - 如何获得点击事件的最近点
问题描述
在这个 Highcharts 图表 ( jsfiddle ) 中有两个事件。mouseOver
和click
通过在图表上水平移动鼠标,工具提示和mouseOver
事件会捕捉到图表上最近的点。clicking
我怎样才能在图表上的任何地方得到这一点?
tooltip: {
shared: true
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function() {
console.log( 'click', this.x, this.y );
},
mouseOver: function() {
console.log( 'mouseover', this.x, this.y );
}
}
}
}
}
在这种情况下,它甚至不会触发点击事件。
为此,我需要将点击事件添加到主图表。
chart: {
events: {
click: function (event) {
console.log( 'click', event.x, event.y );
}
}
}
但是我怎样才能得到最近的点呢?
解决方案
尝试以这种方式使用图表上的点击事件:
chart: {
events: {
click: function() {
console.log(this.hoverPoint)
}
}
},
其中 hoverPoint 是一种附加悬停点的“状态”。
推荐阅读
- jquery - jQuery $.ajax responseJSON 与 responseText 有不同的值
- reactjs - useEffect 懒惰创建的清理函数
- php - 如何使用 php 在终端中运行快速通道?exec() 或 shell_exec()
- python - 变量在周期性任务中不更新
- vba - 如何从文件夹中读取文件并将其作为附件
- c# - 是否可以在异步 Timer 中使用 context.Add(object)?
- matlab - 信号平滑算法(Matlab的移动平均)
- c# - UIElement 不能在不同的名称空间内更改
- c# - 子用户控件中的 WPF 选项卡导航
- excel - Excel 每天自动刷新并将文件保存到我的电脑中