Chart.js axes label font size

2020-02-18 08:35发布

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
      ...
    }]
   }
}

4条回答
趁早两清
2楼-- · 2020-02-18 08:48

Try this is working

     options: {
        scales: {
           xAxes: [{
                   ticks: {
                    fontSize: 10
                   }
                  }]
                }
             }

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-02-18 08:55

Try this simple solution:

myChart.options.scales.yAxes[0].ticks.fontSize = 40 ;

myChart.update();
查看更多
Melony?
4楼-- · 2020-02-18 08:57

Try to see if this will work

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

It doesn't look like scaleFontSize is a valid property.

查看更多
家丑人穷心不美
5楼-- · 2020-02-18 09:03

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 :

enter image description here

查看更多
登录 后发表回答