Chartjs-Getting (X,Y) point on mouse click on chart

1๐Ÿ‘

  onClick: (e) => {

    const canvasPosition = Chart.helpers.getRelativePosition(e, chart);

    // replace .x. and .y. with the id of your axes below

    const dataX = chart.scales.x.getValueForPixel(canvasPosition.x);
    const dataY = chart.scales.y.getValueForPixel(canvasPosition.y);
},

Leave a comment