From: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Date: Wed, 2 Jun 2021 19:48:04 +0000 (+0200) Subject: complete custom legend click sample to also work for pie/doughnut charts (#9219) X-Git-Tag: v3.4.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26f8d7b735503757453c70520534f478b4ceef0c;p=thirdparty%2FChart.js.git complete custom legend click sample to also work for pie/doughnut charts (#9219) --- diff --git a/docs/configuration/legend.md b/docs/configuration/legend.md index 771392803..9f8040c0b 100644 --- a/docs/configuration/legend.md +++ b/docs/configuration/legend.md @@ -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; [