Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js axes label font size

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
      ...
    }]
   }
}
like image 441
dingdingding Avatar asked Jul 08 '16 17:07

dingdingding


People also ask

How do you change the font size on an axis label?

To change the text font for any chart element, such as a title or axis, right–click the element, and then click Font. When the Font box appears make the changes you want.

How to change chart axes label font size with JavaScript?

To change the Chart.js axes label font size with JavaScript, we set the fontSize property. const options = { scales: { yAxes: [ { ticks: { fontSize: 40, }, }, ], }, }; to set the ticks.fontSize property in the yAxes array to set the font size of the y-axis labels.

How do I change the font size on the chart?

There are special global settings that can change all of the fonts on the chart. These options are in Chart.defaults.font. The global font settings only apply when more specific options are not included in the config. For example, in this chart the text will have a font size of 16px except for the labels in the legend. Copied!

Where is the fontsize attribute in chartjs?

The fontSize attribute is actually in scales.xAxes.ticks and not in scales.xAxes as you thought. Show activity on this post. Configuration options and properties for chartjs 3.0 has changed.

How do I label the axis in a chart?

When creating a chart, you want to tell the viewer what data they are viewing. To do this, you need to label the axis. Namespace: options.scales [scaleId].title, it defines options for the scale title. Note that this only applies to cartesian axes. If true, display the axis title. Alignment of the axis title.


2 Answers

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

like image 107
tektiv Avatar answered Oct 16 '22 10:10

tektiv


Configuration options and properties for chartjs 3.0 has changed. Currently I'm using Chartjs 3.1.1. Fonts are used as objects now. In order to change font size of x axis ticks you have to use following configuration.

var options = {
    scales: {
        x: {
            ticks: {
                font: {
                    size: 12,
                }
            }
        }
    }
};

Checkout this jsfiddle sample.

like image 29
rumman0786 Avatar answered Oct 16 '22 09:10

rumman0786