score:1

Accepted answer

chart.js has an example for a html legend on their sample page: https://www.chartjs.org/docs/master/samples/legend/html.html

li.onclick = () => {
        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();
      };

the chart and item here are argument in the plugin callback so if you are implementing it yourself without use of the plugin you will need to reference your own chart object and manage which index you clicked and then call the setdatasetvisibility or toggledatavisibility for that index


Related Query

More Query from same tag