amcharts5
amcharts5 copied to clipboard
V5: overwrite legend click event
Hey for V5, do you know how to replace each legend label's click event with our own user event?
You can disable built-in toggle events by setting clickTarget: "none":
https://www.amcharts.com/docs/v5/concepts/legend/#disabling-toggling
Then you can just add your own click events:
leged.itemContainers.template.events.on("click", function(ev) {
console.log(ev.target);
});
Thanks! clickTarget: "none" also works if I set it with JSON config for legend.settings, right?
Thanks! clickTarget: "none" also works if I set it with JSON config for legend.settings, right?
Yes.
doesn't seem to work while setting up legend.itemContainers.template.events
This is because by the time you add the event, item containers are already created.
You may need to add to actual items:
legend.itemContainers.each(function(container) {
container.events.on("click", .....);
});
Thanks the above solution works great!
One small question on clickTarget: "none": this also disables the hovering (curser: pointer 👆) effect on legend.
Do you know how to show the cursor while disable the original click event?
itemContainers: {
properties: {
template: {
settings: {
x: { type: 'Percent', value: 0 },
centerX: { type: 'Percent', value: 10 },
width: { type: 'Percent', value: 98 },
height: 50,
cursorOverStyle: "pointer",
interactive: true
}
}
}
},