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
...
}]
}
}
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.
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.
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!
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.
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.
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
}
}]
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With