Radar Chart, Chart.js v3.2 labels customization

1.9k Views Asked by At

how can i customize labels in radar chart?

i'm not refer to legend's labels, but the voice at the vertex of the radar chart

in particular font and color

i search a lot but i found soluton for older version, and only for color property

I just tried to use pointLabels property but don't work. Could someone help me?

IMAGE

1

There are 1 best solutions below

1
On BEST ANSWER

This can be achieved through the following options:

scales: {
  r: {
    pointLabels: {
      color: 'green',
      font: {
        size: 20,
        style: 'italic'
      }
    }
  }
}

I must admit that I didn't find the solution in the Chart.js documentation either. Therefore, I logged the entire chart to the console (console.log(chart)) and searched for "scales" to finally find the pointLabels default values.

Please take a look at below runnable sample and see how it works:

new Chart('radar-chart', {
  type: 'radar',
  data: {
    labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
    datasets: [{
      label: 'My First Dataset',
      data: [65, 59, 90, 81, 56, 55, 40],
      fill: true,
      backgroundColor: 'rgba(255, 99, 132, 0.2)',
      borderColor: 'rgb(255, 99, 132)',
      pointBackgroundColor: 'rgb(255, 99, 132)',
      pointBorderColor: '#fff',
      pointHoverBackgroundColor: '#fff',
      pointHoverBorderColor: 'rgb(255, 99, 132)'
    }],
  },
  options: {
    plugins: {
      legend: {
        display: false
      }
    },
    scales: {
      r: {
        pointLabels: {
          color: 'green',
          font: {
            size: 20,
            style: 'italic'
          }
        }
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.2.0/chart.min.js"></script>
<canvas id="radar-chart"></canvas>