使用 Chart.js 检测图表部分上的悬停事件 [英] Detecting hover events over parts of a chart using Chart.js

查看:19
本文介绍了使用 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

这篇关于使用 Chart.js 检测图表部分上的悬停事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆