1👍
You can get the clicked legend by this code. then you can select the same legend. I have created something similar like this with help of SO.
var canvas = document.getElementById('yourChartDiv');
var myChart = new Chart(canvas, chartData);
canvas.onclick = function(evt) {
var activePoint = myChart.getElementAtEvent(evt)[0];
var data = activePoint._chart.data;
var datasetIndex = activePoint._datasetIndex;
var lagend = data.datasets[datasetIndex].label;
//var value = data.datasets[datasetIndex].data[activePoint._index];
};
console.log(legend); // here is the legend
//Now select the bars with same legend.
Hope you can get at least a clue.
- Chartjs-Calling a function for fontSize in Doughnut Chart (typescript)
- Chartjs-ChartJS – How to choose the visible datalabels
Source:stackexchange.com