Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions docs/configuration/legend.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,16 @@ const chart = new Chart(ctx, {

It can be common to want to trigger different behaviour when clicking an item in the legend. This can be easily achieved using a callback in the config object.

:::tip Updated
Starting from Chart.js v4, use `toggleDataVisibility()` and `update()` instead of the old `show()` / `hide()` methods.
:::
Comment on lines +165 to +167
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.


The default legend click handler is:

```javascript
function(e, legendItem, legend) {
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;
}
Comment on lines -169 to -177
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.

legend.chart.toggleDataVisibility(legendItem.index);
legend.chart.update();
}
```

Expand Down