Chartjs-Chartjs updating point titles

1👍

If i’m understanding you correctly you want the title of a tooltip to reflect the x-axis index of the data in the chart, in which case you can do it like so:

tooltips: {
        callbacks: {
            title: function (tooltipItems) {
                return "Point " + (tooltipItems[0].index + 1);
            }
        }
    }

Because one of the parameters given to title() in the callbacks is an array of tooltips that should be displayed, you can find out what the index is and add 1, which will reflect it’s position. This way you can also scrap Name() and the i variable.

But bear in mind that this reflects position on the x-axis, meaning if you have more than one point at the same place on the x-axis then they will both have the same title.

Leave a comment