[Chartjs]-How to get any y value for specified x in chart.js?

-1๐Ÿ‘

A simple to way to get this done is binding the canvas for onClick event, and use the following code, also here is a working fiddle -> http://jsfiddle.net/Lzo5g01n/4/

document.getElementById("myChart").addEventListener("click", function(e) {
  var element = myChart.getElementAtEvent(e)[0];
  if (element) {
    alert(myChart.config.data.datasets[element._datasetIndex].data[element._index]);
  }
});

Leave a comment