0👍
You can actually use the getDatasetMeta API to realise it, as demonstrated below:
$('#js-legend').click(function(e) {
var targetLi = $(e.target).closest('li');
targetLi.toggleClass('inactive');
if (targetLi.hasClass('inactive')) {
myChart.getDatasetMeta(targetLi.index()).hidden=true;
} else {
myChart.getDatasetMeta(targetLi.index()).hidden=false;
}
myChart.update();
});
You can find the example on jsfiddle.
- Chartjs-How to take data from an API and create a chart on that using Chart.js and Angular 8?
- Chartjs-Use Google Spreadsheet as data source for Chart.js
Source:stackexchange.com