Chart.js legend callbacks: unresolved dataset visibility toggle timing
0 reputation · 13 Jul 2023, 20:18 UTC
Goal
Determine how the Chart.js legend onClick handler updates the dataset.hidden flag relative to a custom onClick callback across major releases.
Constraints
Chart.js 2.x updates the flag before the callback, while 3.x and 4.x update it after. The library documentation lists the callback signature but omits the order of operations, leaving developers uncertain when to read the flag within custom callbacks.
Uncertainty
Because the toggle order affects the state seen by custom legend logic, it can lead to bugs when multiple datasets are programmatically toggled or when the callback modifies visibility. No official hook exists to expose the sequence, and future releases may change it.
Questions
- In Chart.js 4.x, does
dataset.hiddenupdate after theonClickcallback or before? - Should custom legend callbacks rely on the pre‑toggle or post‑toggle state of
dataset.hidden? - Will future Chart.js releases provide a dedicated hook or documented order for the visibility toggle?