Chartjs-How to add label for each data from dataset in chartjs 2.9.4?

0👍

Have you read about the datalabels plugin for chart.js? You can find more info here.

After importing that library, you can update your chart config as follows:

options: {
plugins: {
    datalabels: {
        align: 'end',
        anchor: 'end',
        color: 'black',
        formatter: function(value, context) {
            return context.chart.data.labels[context.dataIndex] + ': ' + value;
        }
    }
}
}

The formatter attribute is the crucial part here.

Leave a comment