From a87175f1195a87fbf0b4f150d305348a63c4098b Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sat, 8 May 2021 01:10:18 -0400 Subject: [PATCH] HTML legend handles doughnut/pie charts (#9044) * HTML legend handles doughnut/pie charts * Fix lint error --- docs/samples/legend/html.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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(); }; -- 2.47.3