How do I make the data label colors different?

Consider the chart here:

I’d like to make the numbers above the blue line also blue and the numbers above the red line also red, but haven’t been successful. Thoughts?

You can do this using plugins.datalabels.color. Here’s your updated example

    "plugins": {
      "datalabels": {
        "anchor": "center",
        "align": "top",
        "color": function(context) {
          var index = context.dataIndex;
          var datasetIndex = context.datasetIndex;
          var value = context.dataset.data[index];

          // If the dataset is Low Temp (0) 
          if (datasetIndex === 0) {
            return 'rgb(0, 0, 255)';
          }

          // If the dataset is High Temp (1)
          if (datasetIndex === 1) {
            return 'rgb(255, 0, 0)';
          }

          // Default color
          return 'rgb(0, 0, 0)';
        },
        // ...

1 Like