简体   繁体   中英

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.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

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().

I've opened a request. I will update if they add this event natively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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