you need to use the .getelementatevent() prototype method instead of .getelementsatevent(). the difference being the first only returns the single point that you clicked whereas the other returns all points at the x axis for that click.

here is an example.

document.getelementbyid("canvas").onclick = function(evt) {
  var activepoint = myline.getelementatevent(event);

  // make sure click was on an actual point
  if (activepoint.length > 0) {
    var clickeddatasetindex = activepoint[0]._datasetindex;
    var clickedelementindex = activepoint[0]._index;
    var label =[clickedelementindex];
    var value =[clickeddatasetindex].data[clickedelementindex];     
    alert("clicked: " + label + " - " + value);

you can see a demonstration at this codepen.


you have to change your label variable assignment from,

var label =[firstpoint._index];


var label =[firstpoint._index].label;

and you may also need to change your alert statment as,

alert(label + ": " + value.x);

here is the working demo:

hope this helps!.

Related Query

More Query from same tag