Chartjs-Click on Element Inside Doughnut Chart

0👍

It turned to be not a Chart.js issue, but a <canvas> element nature that prevents events.

One possible solution would be to get x,y coordinates offset from the chart.js click event and do some math to represent the element inside the chart canvas.

For example:

var x = e.offsetX 
var y = e.offsetY

if (x > 120 && x < 130 && y > 85 && y < 100)
   element_clicked()

Good reads:

Hit Region Detection For HTML5 Canvas And How To Listen To Click Events On Canvas Shapes

StackOverflow: How do I add a simple onClick event handler to a canvas element?

Leave a comment