docs(legend): update default onClick example for v4 (fixes #12144)#12148
Open
F-A-N-D-E wants to merge 1 commit intochartjs:masterfrom
Open
docs(legend): update default onClick example for v4 (fixes #12144)#12148F-A-N-D-E wants to merge 1 commit intochartjs:masterfrom
F-A-N-D-E wants to merge 1 commit intochartjs:masterfrom
Conversation
LeeLenaleee
reviewed
Nov 16, 2025
Comment on lines
+165
to
+167
| :::tip Updated | ||
| Starting from Chart.js v4, use `toggleDataVisibility()` and `update()` instead of the old `show()` / `hide()` methods. | ||
| ::: |
Collaborator
There was a problem hiding this comment.
This can be left out since it is in the V4 docs and is something for the migration guide.
Comment on lines
-169
to
-177
| const index = legendItem.datasetIndex; | ||
| const ci = legend.chart; | ||
| if (ci.isDatasetVisible(index)) { | ||
| ci.hide(index); | ||
| legendItem.hidden = true; | ||
| } else { | ||
| ci.show(index); | ||
| legendItem.hidden = false; | ||
| } |
Collaborator
There was a problem hiding this comment.
This is the code that is currently in the source file:
Chart.js/src/plugins/plugin.legend.js
Line 645 in 2898a6d
So this change is not correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default legend onClick example used outdated methods (
show/hide)which caused a TypeError in Chart.js v4.
Updated to use
toggleDataVisibility()andupdate()instead.Fixes #12144.