首页 > 解决方案 > 鼠标悬停在图表上发出的 event.point.index 有什么意义?

问题描述

我试图在一个简单的折线图上确定用户鼠标位置的最近 x 值。有没有办法做到这一点?

我已经尝试向图表实例添加一个 pointMouseOver 和 pointsHover 侦听器,虽然它们发出某种索引,但索引的数量远远超过图表中 x 值的数量(我的图表有大约 600 个 x 值,最大发出的指数约为 1000)。

this.chart.listen('pointMouseOver', function (event) {
                        console.log(event.iterator.getIndex())
                        console.log(event)
                    })

返回一些任意索引而不是最接近的 x 值。

标签: anychart

解决方案


在查看图表 API 参考时设法自己回答了我的问题 - 要在 pointsHover 上获取最接近的 x 值,请调用 event.point.get('x')。https://playground.anychart.com/api/_samples/anychart.enums.EventType.pointsHover


推荐阅读