Skip to content

Commit

Permalink
HTML legend handles doughnut/pie charts (#9044)
Browse files Browse the repository at this point in the history
* HTML legend handles doughnut/pie charts

* Fix lint error
  • Loading branch information
etimberg committed May 8, 2021
1 parent 9a78770 commit a87175f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/samples/legend/html.md
Expand Up @@ -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();
};

Expand Down

0 comments on commit a87175f

Please sign in to comment.