Building a dynamic line chart using Chart.js with the capability of up to 19 datasets. The issue arises when there are less than 19 datasets, as the legend still displays for these unused datasets. Previously, a function was used in Chart.js 2.6.0 options to filter out these unused datasets:
legend: {
labels: {
filter: function(item, chart) {
return !item.text.includes('unused');
}
}
}
However, this solution no longer works with Chart.js 3.2.0.
Is there a way to achieve the same functionality with Chart.js 3.2.0?
This is how the datasets are currently assigned:
for (i = 0; i < datasets.length; i++){
myChart.data.datasets[i].data = datasets[i];
myChart.data.datasets[i].label = labels[i];
};
for (j = datasets.length; j < 19; j++){
myChart.data.datasets[j].label = 'unused';
};
myChart.update();