From: Evert Timberg Date: Sat, 8 May 2021 05:10:18 +0000 (-0400) Subject: HTML legend handles doughnut/pie charts (#9044) X-Git-Tag: v3.3.0~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a87175f1195a87fbf0b4f150d305348a63c4098b;p=thirdparty%2FChart.js.git HTML legend handles doughnut/pie charts (#9044) * HTML legend handles doughnut/pie charts * Fix lint error --- diff --git a/docs/samples/legend/html.md b/docs/samples/legend/html.md index ab0add511..a80f05c1d 100644 --- a/docs/samples/legend/html.md +++ b/docs/samples/legend/html.md @@ -45,7 +45,13 @@ const htmlLegendPlugin = { li.style.marginLeft = '10px'; li.onclick = () => { - chart.setDatasetVisibility(item.datasetIndex, !chart.isDatasetVisible(item.datasetIndex)); + const {type} = chart.config; + if (type === 'pie' || type === 'doughnut') { + // Pie and doughnut charts only have a single dataset and visibility is per item + chart.toggleDataVisibility(item.index); + } else { + chart.setDatasetVisibility(item.datasetIndex, !chart.isDatasetVisible(item.datasetIndex)); + } chart.update(); };