Javascript Chart.js 轴标签字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38272444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:16:05  来源:igfitidea点击:

Chart.js axes label font size

javascriptchart.js

提问by dingdingding

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

在chart.js中,如何在不触及全局配置的情况下为x轴标签设置字体大小?

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

我已经尝试将“scaleFontSize”选项设置为我的选项对象。我也试过设置:

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

回答by tektiv

The fontSizeattribute is actually in scales.xAxes.ticksand not in scales.xAxesas you thought.

fontSize属性实际上是在scales.xAxes.ticks而不是scales.xAxes您想象的那样。

So you just have to edit the attribute like this :

所以你只需要像这样编辑属性:

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



你可以看到一个 fully working example in this jsFiddle这个 jsFiddle 中的完整工作示例,这是它的结果:

enter image description here

在此处输入图片说明

回答by NAVEEN KUMAR

Try this is working

试试这个工作

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

回答by Richard Hamilton

Try to see if this will work

尝试看看这是否有效

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

It doesn't look like scaleFontSizeis a valid property.

它看起来scaleFontSize不是一个有效的属性。

回答by Abdul Hameed

Try this simple solution:

试试这个简单的解决方案:

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

myChart.update();