简体   繁体   English

如何向chart.js图例添加事件?

[英]How can I add an event to chart.js legend?

Based on this post I've been able to add the event, but it's not triggered. 根据这篇文章,我已经能够添加事件,但它没有被触发。 Any idea why? 知道为什么吗? I'm using the default chart.js legend. 我正在使用默认的chart.js图例。

Chart.helpers.each(vm.chart.legend.legendItems, function(legendNode, index) {
  Chart.helpers.addEvent(legendNode, 'mouseover', function() {
    console.log('event triggered!');
  });
});

ALT

Brief code description : Adds the event to every legend item. 简要说明 :将事件添加到每个图例项目。

Using : angularjs and chartjs 2.1.6 使用 :angularjs和chartjs 2.1.6

I've got this answer from one of the developers. 我从其中一位开发者那里得到了这个答案 Currently it's not possible to add custom events to the canvas legend. 目前,无法向画布图例添加自定义事件。 You must create you own html legend using myChartInstance.generateLegend(). 您必须使用myChartInstance.generateLegend()创建自己的html图例。

I've opened a request. 我已经打开了一个请求。 I will update if they add this event natively. 如果他们原生添加此事件,我会更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM