]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
complete custom legend click sample to also work for pie/doughnut charts (#9219)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Wed, 2 Jun 2021 19:48:04 +0000 (21:48 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Jun 2021 19:48:04 +0000 (22:48 +0300)
docs/configuration/legend.md

index 771392803ac0fc2641c88b423cb2e43862ca5e00..9f8040c0be5706b066edb722f6a8a7852acc62d7 100644 (file)
@@ -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;
         [