[Chartjs]-Chart.js: Get point index from chart.getPointsAtEvent(e)

2👍

You should be able to do an indexOf (instead of a label lookup) because it refers to the exact same object in the points collection

canvas.onclick = function (evt) {
    var points = chart.getPointsAtEvent(evt);
    alert(chart.datasets[0].points.indexOf(points[0]));
};

Also, for a multi series line chart getPointsAtEvent(evt) returns points from all datasets. So the same code would work irrespective of how many datasets you have or which of the datasets you click on.

Fiddle – http://jsfiddle.net/yxz2sjam/

Leave a comment