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

查看:162
本文介绍了使用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天全站免登陆