javascript - chart js 停止图表区域功能
问题描述
我正在使用图表 js 插件。我正在使用两个功能。第一个函数在用户单击图表时调用。第二个函数在用户单击图例区域时调用。检查以下示例。
当我单击图例区域时,图表区域功能也可以使用。我需要限制它。请检查我的样品。你可以理解我的意思。
图表区域功能:
onClick: function(e, array){
alert('clicked on chart area')
}
图例区域功能:
onClick: function(e, legend_item){
alert('clicked on legend')
}
演示 演示
解决方案
这是一种解决方案。我们使用 this.chart.chartArea 检查点击是否在图表区域内。这计算了图表区域的偏移量,我们可以看看它是否在里面。
onClick: function(e, array){
const { left, right, top, bottom} = this.chart.chartArea;
if(
event.offsetX > left &&
event.offsetX < right &&
event.offsetY > top &&
event.offsetY < bottom
){
alert('clicked on chart area')
}
},
推荐阅读
- php - 制作 CMS 用户个人资料页面
- java - 线程销毁后,锁如何保留在线程持有的对象上?
- sbt - 获取系统属性在调试日志级别无法正常工作
- memory-leaks - RxJS:在 takeUntil 之后使用重复创建订阅泄漏
- angular - 如何使用 karma jasmine 对依赖于另一个函数的函数进行单元测试
- php - Cookie 不会设置,没有结果
- python - 在 python 中读取德语 csv 文件的问题
- opencv - 来自应用程序的 OpenCv + Gstreamer,初始延迟 30 秒
- amazon-web-services - 确保在 AWS S3 同步期间数据不会丢失
- php - 如何通过 agi php 写入文件?