Chartjs-How to highlight the bars in stacked bar chart of chart.js on clicking a legend

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.

Leave a comment