Axis
Edit this pageAxes provide axis lines, ticks, and labels to convey how a positional range represents a data range. Simply put, axes visualize scales.
By default, Vega-Lite automatically creates axes with default properties for x
and y
channels when they encode data fields.
User can set the axis
property of x- or y-field definition to an object to customize axis properties or set axis
to null
to remove the axis.
Besides axis
property of a field definition, the configuration object (config
) also provides axis config (config: {axis: {...}}
) for setting default axis properties for all axes.
Documentation Overview
Axis Properties
// Single View Specification
{
"data": ... ,
"mark": ... ,
"encoding": {
"x": {
"field": ...,
"type": ...,
"axis": { // Axis
...
},
...
},
"y": ...,
...
}
}
To customize axis, an axis
object in an encoding channel’s definition can contain the following groups of properties:
General
Property | Type | Description |
---|---|---|
domain | Boolean |
A boolean flag indicating if the domain (the axis baseline) should be included as part of the axis. Default value: |
grid | Boolean |
A boolean flag indicating if grid lines should be included as part of the axis Default value: |
maxExtent | Number |
The maximum extent in pixels that axis ticks and labels should use. This determines a maximum offset value for axis titles. Default value: |
minExtent | Number |
The minimum extent in pixels that axis ticks and labels should use. This determines a minimum offset value for axis titles. Default value: |
orient | String |
The orientation of the axis. One of Default value: |
offset | Number |
The offset, in pixels, by which to displace the axis from the edge of the enclosing group or data rectangle. Default value: derived from the axis config’s |
position | Number |
The anchor position of the axis in pixels. For x-axis with top or bottom orientation, this sets the axis group x coordinate. For y-axis with left or right orientation, this sets the axis group y coordinate. Default value: |
zindex | Number |
A non-positive integer indicating z-index of the axis.
If zindex is 0, axes should be drawn behind all chart elements.
To put them in front, use Default value: |
See also: General Axis Config.
Labels
Property | Type | Description |
---|---|---|
format | String |
The formatting pattern for labels. This is D3’s number format pattern for quantitative fields and D3’s time format pattern for time field. See the format documentation for more information. Default value: derived from numberFormat config for quantitative fields and from timeFormat config for temporal fields. |
labels | Boolean |
A boolean flag indicating if labels should be included as part of the axis. Default value: |
labelAngle | Number |
The rotation angle of the axis labels. Default value: |
labelOverlap | Boolean | String | String |
The strategy to use for resolving overlap of axis labels. If Default value: |
labelPadding | Number |
The padding, in pixels, between axis and text labels. |
See also: Axis Labels Config and guide-label
style config (common styles for axis, legend, and header labels).
Ticks
Property | Type | Description |
---|---|---|
ticks | Boolean |
Boolean value that determines whether the axis should include ticks. |
tickCount | Number |
A desired number of ticks, for axes visualizing quantitative scales. The resulting number may be different so that values are “nice” (multiples of 2, 5, 10) and lie within the underlying scale’s range. |
tickSize | Number |
The size in pixels of axis ticks. |
values | Number[] | String[] | Boolean[] | DateTime[] |
Explicitly set the visible axis tick values. |
See also: Axis Ticks Config.
Title
Property | Type | Description |
---|---|---|
title | String | Null |
A title for the field. If Default value: derived from the field’s name and transformation function ( Notes: 1) You can customize the default field title format by providing the [ 2) If both field definition’s |
titleMaxLength | Number |
Max length for axis title if the title is automatically generated from the field’s description. |
titlePadding | Number |
The padding, in pixels, between title and axis. |
For example, the following plot has a customized x-axis title.
See also: Axis Title Config and guide-title
style config (common styles for axis, legend, and header titles).
Axis Config
// Top-level View Specification
{
...
"config": {
"axis": : ...,
"axisX": : ...,
"axisY": : ...,
"axisLeft": : ...,
"axisRight": : ...,
"axisTop": : ...,
"axisBottom": : ...,
"axisBand": : ...,
...
}
}
Axis configuration defines default settings for axes. Properties defined under the "axis"
property in the top-level config
object are applied to all axes.
Additional property blocks can target more specific axis types based on the orientation ("axisX"
, "axisY"
, "axisLeft"
, "axisTop"
, etc.) or band scale type ("axisBand"
). For example, properties defined under the "axisBand"
property will only apply to axes visualizing "band"
scales. If multiple axis config blocks apply to a single axis, type-based options take precedence over orientation-based options, which in turn take precedence over general options.
General
Property | Type | Description |
---|---|---|
bandPosition | Number |
An interpolation fraction indicating where, for |
domain | Boolean |
A boolean flag indicating if the domain (the axis baseline) should be included as part of the axis. Default value: |
domainColor | String |
Color of axis domain line. Default value: (none, using Vega default). |
domainWidth | Number |
Stroke width of axis domain line Default value: (none, using Vega default). |
maxExtent | Number |
The maximum extent in pixels that axis ticks and labels should use. This determines a maximum offset value for axis titles. Default value: |
minExtent | Number |
The minimum extent in pixels that axis ticks and labels should use. This determines a minimum offset value for axis titles. Default value: |
See also: General Axis Properties.
Grid
Property | Type | Description |
---|---|---|
grid | Boolean |
A boolean flag indicating if grid lines should be included as part of the axis Default value: |
gridColor | String |
Color of gridlines. |
gridDash | Number[] |
The offset (in pixels) into which to begin drawing with the grid dash array. |
gridOpacity | Number |
The stroke opacity of grid (value between [0,1]) Default value: ( |
gridWidth | Number |
The grid width, in pixels. |
Labels
Property | Type | Description |
---|---|---|
labels | Boolean |
A boolean flag indicating if labels should be included as part of the axis. Default value: |
labelAngle | Number |
The rotation angle of the axis labels. Default value: |
labelColor | String |
The color of the tick label, can be in hex color code or regular color name. |
labelFont | String |
The font of the tick label. |
labelFontSize | Number |
The font size of the label, in pixels. |
labelLimit | Number |
Maximum allowed pixel width of axis tick labels. |
labelOverlap | Boolean | String | String |
The strategy to use for resolving overlap of axis labels. If Default value: |
labelPadding | Number |
The padding, in pixels, between axis and text labels. |
The shortTimeLabels
property is also available for the general axis config (config.axis
), but not for specific axis config (e.g., config.axisX
).
Property | Type | Description |
---|---|---|
shortTimeLabels | Boolean |
Whether month names and weekday names should be abbreviated. Default value: |
See also: Axis Labels Properties and guide-label
style config (common styles for by axis, legend, and header labels).
Ticks
Property | Type | Description |
---|---|---|
ticks | Boolean |
Boolean value that determines whether the axis should include ticks. |
tickColor | String |
The color of the axis’s tick. |
tickRound | Boolean |
Boolean flag indicating if pixel position values should be rounded to the nearest integer. |
tickSize | Number |
The size in pixels of axis ticks. |
tickWidth | Number |
The width, in pixels, of ticks. |
See also: Axis Tick Properties.
Title
Property | Type | Description |
---|---|---|
titleAlign | String |
Horizontal text alignment of axis titles. |
titleAngle | Number |
Angle in degrees of axis titles. |
titleBaseline | String |
Vertical text baseline for axis titles. |
titleColor | String |
Color of the title, can be in hex color code or regular color name. |
titleFont | String |
Font of the title. (e.g., |
titleFontWeight | String |
Font weight of the title.
This can be either a string (e.g |
titleFontSize | Number |
Font size of the title. |
titleLimit | Number |
Maximum allowed pixel width of axis titles. |
titleMaxLength | Number |
Max length for axis title if the title is automatically generated from the field’s description. |
titlePadding | Number |
The padding, in pixels, between title and axis. |
titleX | Number |
X-coordinate of the axis title relative to the axis group. |
titleY | Number |
Y-coordinate of the axis title relative to the axis group. |
See also: Axis Title Properties and guide-title
style config (common styles for axis, legend, and header titles).