Scale defaults

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
color = 'rgba(0,0,0,0.1)
lineWidth = 1
drawTicks: true
drawOnChartArea = true
offsetGridLines = false

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,
labelString = ''
lineHeight = 1.2
padding: {top: 4, bottom: 4}

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
beginAtZero = false
autoSkip = true
reverse = false
Options in Charts.defaults.scales that can be configured for scales of all charts.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset