Chartjs-ChartJS: Update tooltip

1👍

I found a solution:

myNewChart.datasets[0].points.forEach(function(point) {
  point.datasetLabel = 'updated label';
});

This might also be the way it should be done. Chart.js documentation of update method says you should set myLineChart.datasets[0].points[2].value = 50; to change the value. That’s confusing cause on creation dataset expects the values in data property. points is generated by Chart.Line Class on init. Naming may be different for other chart types (eg. it’s bars for a bar chart).

I’m not quite sure if myLineChart.datasets[0].label value is used somewhere or if could be unchanged.

0👍

I could solve your problem by changing the original data object (data.datasets[0].label=’updated label’) then running myNewChart.initialize(data).

0👍

var option = {
    plugins: {
        tooltip: {
            callbacks: {
                label: function (context) {
                    //console.log(context);
                    label = 'new string ' + context.label + ', ' + context.dataIndex;
                    return label;
                }
            }
        }
    }
};

myChart.options = option;

ToolTips / Points Events are configurable with chartJS options

enter image description here

Find more here: https://www.chartjs.org/docs/latest/configuration/tooltip.html

Leave a comment