Detecting hover events over parts of a chart using Chart.js(使用 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 检测图表部分上的悬停事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Chart.js 检测图表部分上的悬停事件


基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01