[Chartjs]-How to make doughnut chart portions, buttons

2👍

I think you’re looking for the getSegmentsAtEvent(evt) method.

canvas.onclick = function(evt){
    var activePoints = myDoughnutChart.getSegmentsAtEvent(evt);
    // => activePoints is an array of segments on the canvas that are at the same position as the click event.
};

If activePoints is empty, that means you can just return because no segment was clicked. Otherwise, go ahead and draw your tooltip.

Leave a comment