ChartJS V3 雷达图标签字体大小

4
var myChart = new Chart(ctx, {
            type: 'radar',
            data: chartData,
            options: {
                scale: {
                    min: 0,
                    max: 5,
                    stepSize: 1
                },
                scales: {
                    r: {
                        pointLabels: {
                            fontSize: 100
                        }
                    }
                },
                elements: {
                    line: {
                        borderWidth: 3
                    }
                }
            }
        })

我试图改变雷达图上点标签的字体大小。看起来这是应该按照的方法,但对我来说并没有起作用。非常感谢任何帮助。


这个回答解决了你的问题吗?雷达图,Chart.js v3.2标签自定义 - uminder
1个回答

13

在V3中,他们引入了一个font对象来代替单独的属性,因此你需要像这样放置:

r: {
  pointLabels: {
    font: {
      size: 100
    }
  }
}

示例:

var options = {
  type: 'radar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      r: {
        pointLabels: {
          font: {
            size: 100
          }
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.2.0/chart.js"></script>
</body>

字体文档: https://www.chartjs.org/docs/latest/general/fonts.html


谢谢,这是对我有效的完整配置:options: { scales: { // ticks: { // beginAtZero: true, // max: 4, // min: 0, // stepSize: 1, // }, r: { pointLabels: { font: { size: 8, }, }, }, }, - Khaled Boussoffara

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接