Skip to content

Conversation

@F-A-N-D-E
Copy link

The default legend onClick example used outdated methods (show / hide)
which caused a TypeError in Chart.js v4.
Updated to use toggleDataVisibility() and update() instead.
Fixes #12144.

Comment on lines +165 to +167
:::tip Updated
Starting from Chart.js v4, use `toggleDataVisibility()` and `update()` instead of the old `show()` / `hide()` methods.
:::
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the code that is currently in the source file:

onClick(e, legendItem, legend) {

So this change is not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The example for overriding legend onClick is outdated

2 participants