The example for overriding legend onClick is outdated
- Dominant language
- JavaScript
- Stars
- 67.7k
- Forks
- 11.9k
- Avg merge
- 7h 39m
- Merged PRs (30d)
- 5
Description
### Documentation Is:
- [ ] Missing or needed?
- [ ] Confusing
- [ ] Not sure?
### Please Explain in Detail...
Concerning https://www.chartjs.org/docs/latest/configuration/legend.html
The example for overriding legend onClick is outdated. The code throws error `Uncaught TypeError: Cannot read properties of null (reading '_resolveAnimations'`
it is currently:
``` 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;
}
}
````
### Your Proposal for Changes
It should be
``` javascript
legend.chart.toggleDataVisibility(legendItem.index);
legend.chart.update();
```
### Example
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.