[Chartjs]-Chart.js custom tooltipTemplate index

3👍

You can use a function instead of a template string

...
tooltipTemplate: function (d) {
    return data.websites[data.labels.indexOf(d.label)]
},
...

Note that this requires the labels to be unique, or if there are duplicate labels that it not matter which one is active (for instance, in your data, the first 3 labels are the same but that won’t cause any problems because the first 3 entries in the websites array too are the same. If they were different this method will not work)

Leave a comment