Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change label color for line charts.js?

I try to chanage a color of line lables:

exmaple of label pic

The line has settings:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 const linedataset = {
      type: 'line',
      label: 'label',
      data: xavarage,
      order: 1,
      borderColor: 'rgb(225, 54, 54)',
      backgroundColor: lineBackground,
    };

And common settings are:

const chartoptions = {
      hoverBackgroundColor,
      backgroundColor,
      responsive: true,
      scales: {
        x: {},
        y: {
          min: 0,
        },
      },
      plugins: {
        title: {
          display: true,
          text: this.selectedCategory?.full,
          font: {
            size: 20,
          },
        },
        datalabels: {
          anchor: 'end',
          align: 'end',
        },
      },
    };

I have tried to usse the following code:

options: {
   legend: {
     color: "#ccc"
   }
}

But it does not work too. How to set color of label text (line graphic)?

>Solution :

Your chart uses chartjs-plugin-datalabels. Therefore, you need to define color inside datalabels as follows:

datalabels: {
  color: '#ccc',
  anchor: 'end',
  align: 'end'
},
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading