Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom legend onClick example #9219

Merged
merged 1 commit into from Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/configuration/legend.md
Expand Up @@ -171,12 +171,19 @@ Lets say we wanted instead to link the display of the first two datasets. We cou

```javascript
var defaultLegendClickHandler = Chart.defaults.plugins.legend.onClick;
var pieDoughnutLegendClickHandler = Chart.controllers.doughnut.overrides.plugins.legend.onClick;
var newLegendClickHandler = function (e, legendItem, legend) {
var index = legendItem.datasetIndex;
var type = legend.chart.config.type;

if (index > 1) {
// Do the original logic
defaultLegendClickHandler(e, legendItem, legend);
if (type === 'pie' || type === 'doughnut') {
pieDoughnutLegendClickHandler(e, legendItem, legend)
} else {
defaultLegendClickHandler(e, legendItem, legend);
}

} else {
let ci = legend.chart;
[
Expand Down