Chartjs-How to compute x,y values from a click event using x,y pixel coordinates in ChartJS?

1๐Ÿ‘

I found at least a way to extract the y-axis value. The computation of the x-axis value should be similar:

//inside the click callback...
var scaler=that.chart.scales['y-axis-0'];
var chart_height_px=scaler.bottom+scaler.top;

var y=evt.clientY-that.canvas[0].getBoundingClientRect().top-scaler.top;

var yval=scaler.max-y/scaler.height*(scaler.max-scaler.min);
console.log("value clicked: %o, ypx: %o", yval, y);
that.trigger("onTickerYClick", yval);

Leave a comment