Chart.js 轴标签字体大小

2022-01-22 00:00:00 javascript chart.js

In chart.js how can I set the set the font size for just the x axis labels without touching global config?

I've already tried setting the 'scaleFontSize' option my options object. I've also tried setting:

{
  ...
  scales: {
    xAxes: [{
      scaleFontSize: 40
      ...
    }]
   }
}

解决方案

The fontSize attribute is actually in scales.xAxes.ticks and not in scales.xAxes as you thought.

So you just have to edit the attribute like this :

var options = {
    scales: {
        yAxes: [{
            ticks: {
                fontSize: 40
            }
        }]
    }
}


You can see a fully working example in this jsFiddle and here is its result :

相关文章