使用 Chart.js 检测图表部分上的悬停事件
我使用 Chart.js 制作了一个饼图,我想检测一个段何时悬停在上面.我发现了很多关于操纵悬停在段上时出现的工具提示的文档,但没有关于在工具提示出现时执行其他操作的文档.这可能吗?
I've made a pie chart using Chart.js, and I'd like to detect when a segment is hovered over. I've found plenty of documentation regarding manipulating the tooltips that appear when hovering over segments, but nothing regarding doing something else when a tooltip would appear. Is this possible?
推荐答案
没有...
ChartJS API 中没有任何内容可以覆盖或扩展工具提示,
There's nothing in the ChartJS API to override or extend the tooltip,
但是,一种解决方法...
你可以修改Chart.Tooltip
类的draw
方法.当工具提示通常由 ChartJS 呈现时,这将允许您做其他事情".
You can modify the draw
method of the Chart.Tooltip
class. This would allow you to "do something else" when the tooltip would normally be rendered by ChartJS.
您要绑定的绘图方法从此处源代码的第 1351 行开始:
The draw method you want to tie into starts at line 1351 of the source here:
https://github.com/nnnick/Chart.js/blob/master/src/Chart.Core.js
相关文章