chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.94k stars 11.89k forks source link

add click (and other) event handle to labels #11827

Closed Offbeatmammal closed 5 days ago

Offbeatmammal commented 5 days ago

Feature Proposal

I know there are some hacky ways to trap a generalised onClick for the canvas and work out if the click happened in the area of a label, but I've not found a clean solution (that works reliably for both horizontal and vertical axes) though happy to explore any recommendations.

our two use-cases are:

Possible Implementation

to fit with the current model, extending It's possible that the existing .getElementsAtEventForMode to treat the labels as elements would be the 'purer' mechanism, though I'd also love to see onClick / onHover methods as options as part of the data.labels definition

LeeLenaleee commented 5 days ago

Duplicate of: https://github.com/chartjs/Chart.js/issues/9602, https://github.com/chartjs/Chart.js/issues/9627 You can also look at this SO answer for how to write a custom plugin to do all the detection: https://stackoverflow.com/a/75438712/8682983

Offbeatmammal commented 3 days ago

Duplicate of: #9602, #9627 You can also look at this SO answer for how to write a custom plugin to do all the detection: https://stackoverflow.com/a/75438712/8682983

that SO solution appears to work for 3.x but not 4.x