Ng2-charts: Change label color

Created on 3 Aug 2018  路  5Comments  路  Source: valor-software/ng2-charts

Is it possible to change the color of labels (axis labels, legend labels?). Seems to be a default grey.

charts.js does provide an option inside the labels object and the legend object - would be fantastic if these options was exposed in the ng2-charts library.

Most helpful comment

Hi @suparnavg,

There are some options to update the labels color. Check my code below; it provides you an example of a chart options object.

 {
    responsive: true,
    title: {
      display: true,
      text: 'Your chart title',
      fontColor: 'black',  // chart title color (can be hexadecimal too)
    },
    scales: {
      xAxes: [{
        stacked: true,
        ticks: {
          fontColor: 'black',  // x axe labels (can be hexadecimal too)
        },
        gridLines: {
          color: '#5f5e5e'  // grid line color (can be removed or changed)
        }
      }],
      yAxes: [{
        stacked: true,
        ticks: {
          fontColor: 'black',  // y axes numbers color (can be hexadecimal too)
          min: 0,
          beginAtZero: true,

        },
        gridLines: {
          color: '#5f5e5e'  // grid line color (can be removed or changed)
        },
        scaleLabel: {
          display: true,
          labelString: 'nombre de DI',
          fontColor: 'black',  // y axe label color (can be hexadecimal too)
        }
      }]
    },
    legend: {
      display: true,
      labels: {
        fontColor: 'black', // legend color (can be hexadecimal too)
      },
    }
 }

Hope it helps,
Kevk.

All 5 comments

Hi @suparnavg,

There are some options to update the labels color. Check my code below; it provides you an example of a chart options object.

 {
    responsive: true,
    title: {
      display: true,
      text: 'Your chart title',
      fontColor: 'black',  // chart title color (can be hexadecimal too)
    },
    scales: {
      xAxes: [{
        stacked: true,
        ticks: {
          fontColor: 'black',  // x axe labels (can be hexadecimal too)
        },
        gridLines: {
          color: '#5f5e5e'  // grid line color (can be removed or changed)
        }
      }],
      yAxes: [{
        stacked: true,
        ticks: {
          fontColor: 'black',  // y axes numbers color (can be hexadecimal too)
          min: 0,
          beginAtZero: true,

        },
        gridLines: {
          color: '#5f5e5e'  // grid line color (can be removed or changed)
        },
        scaleLabel: {
          display: true,
          labelString: 'nombre de DI',
          fontColor: 'black',  // y axe label color (can be hexadecimal too)
        }
      }]
    },
    legend: {
      display: true,
      labels: {
        fontColor: 'black', // legend color (can be hexadecimal too)
      },
    }
 }

Hope it helps,
Kevk.

@DSKevk answer should close this.

Is this also the same when changing the color values inside the chart? Like the pie chart slices have numbers inside it in dark color. I wanted to change it to light font color.

In pieChartOptions write,

public pieChartOptions: ChartOptions = {
plugins: {
datalabels: {
color: '#3c3c3c'
},
}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shenriksen4 picture shenriksen4  路  3Comments

brandonreid picture brandonreid  路  3Comments

dslima90 picture dslima90  路  3Comments

tushartgsit picture tushartgsit  路  5Comments

mrpotato3 picture mrpotato3  路  5Comments