Radar Chart, Chart.js v3.2 labels customization
Asked Answered
C

1

0

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

Constitutionalism answered 28/4, 2021 at 13:1 Comment(0)
B
1

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>
Bree answered 28/4, 2021 at 14:12 Comment(1)
solution of console.log(chart) is a sample solution but that can be used for all problems like mine, when it's not explicit in documentation how to set chart property!Constitutionalism

© 2022 - 2024 — McMap. All rights reserved.