how to change event on legend click in amcharts 5?

1.7k Views Asked by At

the same problem solve is here https://www.amcharts.com/docs/v4/tutorials/activate-deactivate-a-pie-slice-on-legend-click-instead-of-toggling/ , I need to have the same effect but it doesnt work in version 5

1

There are 1 best solutions below

0
On

I had the same problem and it was a really trivial issue, but it took a while to figure this out so here you go: All you need to do is set the legend data AFTER your listener. As commented in the demo below

It's is important to set legend data after all the events are set on template, otherwise events won't be copied

Demo: https://www.amcharts.com/demos/highlighting-line-chart-series-on-legend-hover/

Example

legend.itemContiners.template.events.on("click", function(ev) {
    // Do whatever you want when clicked on Legend
}

legend.data.setAll(chart.series.values)