Scales and grids can be globally configured in the Charts.defaults.scale object. The following table lists the top-level properties and some of the default properties of this object. Some of these defaults are overridden in specific charts. In these cases, changing them in this context may not have any effect:
Object |
Description |
Default properties |
display |
Displays (true) or not (false) the scales for this chart. |
The default is true. |
offset |
Adds extra space to left and right edges of the chart. |
The default is false (overridden to true in bar charts). |
gridLines |
Default properties and callbacks for all scales (some are overridden in specific chart types). See Chapter 5, Scales and Grid Configuration. |
display = true |
scaleLabel |
The default properties and callbacks for all scales (some are overridden in specific chart types). See Chapter 5, Scales and Grid Configuration, for details. |
display = false, |
ticks |
The default properties and callbacks for all scales (some are overriden in specific chart types). See Chapter 5, Scales and Grid Configuration, for details. |
display = true |
For example, the following code will place the same labels on all axes in any charts that use Cartesian axes (bar, horizontalBar, line, scatter, bubble):
Chart.defaults.scale.scaleLabel.display = true;
Chart.defaults.scale.scaleLabel.labelString = 'default';
The display property is available in all scale components. With display: false, you can globally remove ticks, labels, gridlines, and other non-chart information from your default charts, overriding these properties in specific charts only when necessary. This is a good practice and will maximize the data-to-ink ratio of your charts.
The code fragments in this section are from Config/defaults-1-global-config.html, in the GitHub repository for this chapter.