Skip to content

Commit

Permalink
complete custom legend click sample to also work for pie/doughnut cha…
Browse files Browse the repository at this point in the history
…rts (#9219)
  • Loading branch information
LeeLenaleee committed Jun 2, 2021
1 parent b78b7c3 commit 26f8d7b
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit 26f8d7b

Please sign in to comment.