Chartjs-Chart.js – get x-axis label (or index) in onHover event

0👍

onHover: function (evt) {
    const rect = canvas.getBoundingClientRect();
    var x = evt.clientX - rect.left;
    if (x > myChart.chartArea.right)
        x = myChart.chartArea.right;
    const dataX = myChart.scales["x-axis-0"].getValueForPixel(x);
}

Leave a comment