Chartjs-Syntax for chartjs datalabels plugin

0👍

surly this will help
try using formatter function in datalabels

https://chartjs-plugin-datalabels.netlify.app/guide/formatting.html#custom-labels

below return statement will give you the label defined for the point, alter ot as you like

datalabels: {
    formatter: function(value, context) {
      return context.chart.data.labels[context.dataIndex];
    }
  }

this example below is the syntax you need

formatter: function(value, context) {
  return context.dataIndex + ': ' + Math.round(value*100) + '%';
 }

 // label for data at index 0 with value 0.23: "0: 23%"
 // label for data at index 1 with value 0.42: "1: 42%"
// ...

Leave a comment