Loading...
In G2, the Axis component serves as the "ruler" of charts, establishing the mapping relationship between data and visual positions. Through scales, labels, grid lines, and other elements, it helps users intuitively understand data distribution and proportions. It enables you to quickly comprehend the position and numerical values in graphics.
Simply put, axis help us correlate data numbers with positions on the chart, making charts easier to understand.
For example: In a bar chart, the horizontal axis usually represents time, and the vertical axis represents sales. This way, you can see at a glance that "sales were 2 million in March and rose to 3 million in April."
Through the overview content above, I believe you now have a clear understanding of axis. So how exactly do you use them? Next, I'll guide you step by step on how to configure axis.
Configuring axis is like building with blocks - just remember a simple core principle: "Use the axis property, configure by direction, change what needs to be changed where it needs to be changed."
Step 1: Enable Axis (enabled by default)
G2 automatically generates axis based on your data types. No configuration is needed to see basic axis.
chart.options({type: 'interval',width: 500,height: 300,data: [{ id: 1, month: 'March', sales: 200 },{ id: 3, month: 'April', sales: 300 },{ id: 4, month: 'May', sales: 400 },{ id: 5, month: 'June', sales: 500 },{ id: 6, month: 'July', sales: 600 },{ id: 7, month: 'August', sales: 700 },],encode: { x: 'month', y: 'sales', color: 'month' },// No axis configuration needed for automatic axis generation// axis: {},});
Step 2: Configure by Direction
Configure x (horizontal direction) axis
chart.options({type: 'interval',width: 500,height: 300,data: [{ id: 1, month: 'March', sales: 200 },{ id: 3, month: 'April', sales: 300 },{ id: 4, month: 'May', sales: 400 },{ id: 5, month: 'June', sales: 500 },{ id: 6, month: 'July', sales: 600 },{ id: 7, month: 'August', sales: 700 },],encode: { x: 'month', y: 'sales', color: 'month' },// Configure axisaxis: {// Configure horizontal axis propertiesx: {// Configuration parameters and examples can be found below...},},});
Configure y (vertical direction) axis
chart.options({type: 'interval',width: 500,height: 300,data: [{ id: 1, month: 'March', sales: 200 },{ id: 3, month: 'April', sales: 300 },{ id: 4, month: 'May', sales: 400 },{ id: 5, month: 'June', sales: 500 },{ id: 6, month: 'July', sales: 600 },{ id: 7, month: 'August', sales: 700 },],encode: { x: 'month', y: 'sales', color: 'month' },// Configure axisaxis: {// Configure vertical axis propertiesy: {// Configuration parameters and examples can be found below...},},});
Axis can be configured at the Mark level. In G2, each mark has its own axis. If the marks correspond to synchronized scales, the axis will be merged.
({type: 'interval',axis: {x: { labelFormatter: '%0' },y: { tickCount: 5 },},});
Axis can also be configured at the View level. Axis have inheritance properties. Axis declared on views will be passed to marks declared in children
. If the mark has a corresponding channel axis, they merge; otherwise, it has no effect.
({type: 'view',axis: {x: { labelFormatter: '%0' },y: { tickCount: 5 },},});
Hide axis for each channel:
Hide x axis:
({type: 'interval',axis: { x: false }, // Hide x horizontal axis});
Hide y axis:
({type: 'interval',axis: { y: false }, // Hide y vertical axis});
Hide multiple axis
({type: 'interval',axis: false,});
Each axis consists of title, line, tick, label, and grid.
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
title | Set axis title text and style | title | - | |
line | Set axis line display and style | line | - | |
tick | Set axis tick display and style | tick | - | |
label | Set axis label display and style | label | - | |
grid | Set axis grid display and style | grid | - | |
animate | Set axis animation effects | boolean | animate | - | |
position | Set axis position | left | right | top | bottom | x: bottom | y: left |
Title, line, tick, label, and grid configurations are at the same level, not configured as objects, but through prefix + property approach.
For example, to configure label rotation, it's not configured under a label object, but through the following approach:
({axis: {x: {title: 'X Axis Title',labelFontSize: 12,labelFormatter: (d) => `2025-${d}`,transform: [// Rotation{type: 'rotate',optionalAngles: [0, 45, 90], // Try rotating 0°, 45°, 90°recoverWhenFailed: true, // Recover to default angle if rotation fails},],},},});
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
title | Turn off title or set title content | false |string | number | DisplayObject | - | |
titleSpacing | Distance from title to axis | number | (datum, index, data) => number | 10 | |
titlePosition | Title position relative to axis, supports abbreviation like 'top' as 't' | 'top' |'bottom' |'left' |'right' | 'lb' | |
titleFontSize | Title font size | number | (datum, index, data) => number | - | |
titleFontWeight | Title font weight | number | (datum, index, data) => number | - | |
titleFontFamily | Title font family | string | (datum, index, data) => string | - | |
titleLineHeight | Title line height | number | (datum, index, data) => number | 1 | |
titleTextAlign | Title text horizontal alignment | 'center' | 'end' | 'left' | 'right' | 'start' | (datum, index, data) => string | 'start' | |
titleTextBaseline | Title text vertical baseline | 'top' | 'middle' | 'bottom' | 'alphabetic' | 'hanging' | (datum, index, data) => string | 'middle' | |
titleFill | Title text fill color | string | (datum, index, data) => string | - | |
titleFillOpacity | Title text fill opacity | number | (datum, index, data) => number | 1 | |
titleStroke | Title text stroke color | string | (datum, index, data) => string | transparent | |
titleStrokeOpacity | Title text stroke opacity | number | (datum, index, data) => number | 1 | |
titleLineWidth | Title text stroke width | number | (datum, index, data) => number | 0 | |
titleLineDash | Title text stroke dash configuration | number[] | (datum, index, data) => number[] | [] | |
titleOpacity | Title text overall opacity | number | (datum, index, data) => number | 1 | |
titleShadowColor | Title text shadow color | string | (datum, index, data) => string | transparent | |
titleShadowBlur | Title text shadow Gaussian blur coefficient | number | (datum, index, data) => number | 0 | |
titleShadowOffsetX | Title text shadow horizontal offset | number | (datum, index, data) => number | 0 | |
titleShadowOffsetY | Title text shadow vertical offset | number | (datum, index, data) => number | 0 | |
titleCursor | Title text cursor style | string | (datum, index, data) => string | default | |
titleDx | Title text horizontal offset | number | (datum, index, data) => number | 0 | |
titleDy | Title text vertical offset | number | (datum, index, data) => number | 0 |
Configuration approach
({// Configure axisaxis: {// Configure y axisy: {// Axis title configurationtitle: 'Frequency', // Set y-axis titletitleSpacing: 30, // Set spacing between y-axis title and axis linetitlePosition: 'left', // Set y-axis title positiontitleFill: 'steelblue', // Set y-axis title colortitleFontSize: 16, // Set y-axis title font sizetitleFontWeight: 'bold', // Set y-axis title font weighttitleFontFamily: 'Arial', // Set y-axis title font familytitleTextAlign: 'center', // Set y-axis title horizontal alignmenttitleTextBaseline: 'middle', // Set y-axis title vertical baselinetitleOpacity: 0.9, // Set y-axis title overall opacitytitleStroke: '#333', // Set y-axis title stroke colortitleLineWidth: 1, // Set y-axis title stroke widthtitleShadowColor: 'rgba(0,0,0,0.3)', // Set y-axis title shadow colortitleShadowBlur: 3, // Set y-axis title shadow blurtitleShadowOffsetX: 2, // Set y-axis title shadow horizontal offsettitleShadowOffsetY: 2, // Set y-axis title shadow vertical offsettitleDx: 5, // Set y-axis title horizontal offsettitleDy: 0, // Set y-axis title vertical offsettitleCursor: 'pointer', // Set y-axis title cursor style},// Configure x axisx: {// Axis title configurationtitle: 'Letter', // Set x-axis titletitleSpacing: 20, // Set spacing between x-axis title and axis linetitlePosition: 'bottom', // Set x-axis title positiontitleFontSize: 14, // Set x-axis title font sizetitleFontWeight: 'normal', // Set x-axis title font weighttitleFill: '#666', // Set x-axis title colortitleTextAlign: 'center', // Set x-axis title horizontal alignmenttitleOpacity: 1, // Set x-axis title opacitytitleLineHeight: 1.2, // Set x-axis title line heighttitleFillOpacity: 0.8, // Set x-axis title fill opacity},},});
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
line | Whether to show axis line | boolean | false | |
arrow | Whether to show arrow | boolean | true | |
lineExtension | Extension lines on both sides of axis | [number, number] | - | |
lineArrow | Define axis line arrow shape, defaults to arrow shape | DisplayObject | - | |
lineArrowOffset | Arrow offset length | number | 15 | |
lineArrowSize | Arrow size | number | - | |
lineStroke | Axis line stroke color | string | (datum, index, data) => string | - | |
lineStrokeOpacity | Axis line stroke opacity | number | (datum, index, data) => number | - | |
lineLineWidth | Axis line stroke width | number | (datum, index, data) => number | - | |
lineLineDash | Axis line stroke dash configuration, first value is segment length, second is gap distance. Setting [0, 0] means no stroke. | [number,number] | (datum, index, data) => [number,number] | - | |
lineOpacity | Axis line overall opacity | number | (datum, index, data) => number | 1 | |
lineShadowColor | Axis line shadow color | string | (datum, index, data) => string | - | |
lineShadowBlur | Axis line shadow Gaussian blur coefficient | number | (datum, index, data) => number | - | |
lineShadowOffsetX | Axis line shadow horizontal offset | number | (datum, index, data) => number | - | |
lineShadowOffsetY | Axis line shadow vertical offset | number | (datum, index, data) => number | - | |
lineCursor | Axis line cursor style | string | (datum, index, data) => string | default |
Configuration approach
({axis: {x: {line: true, // Whether to show axis linearrow: true, // Whether to show arrowlineArrowOffset: 10, // Arrow offset lengthlineArrowSize: 30, // Arrow sizelineLineWidth: 10, // Axis line stroke widthlineExtension: [5, 5], // Extension lines on both sides of axislineStroke: '#333', // Axis line stroke colorlineStrokeOpacity: 0.8, // Axis line stroke opacitylineLineDash: [5, 5], // Axis line stroke dash configurationlineOpacity: 1, // Axis line overall opacitylineShadowColor: 'rgba(0,0,0,0.3)', // Axis line shadow colorlineShadowBlur: 3, // Axis line shadow Gaussian blur coefficientlineShadowOffsetX: 2, // Axis line shadow horizontal offsetlineShadowOffsetY: 2, // Axis line shadow vertical offsetlineCursor: 'pointer', // Axis line cursor style},y: {line: true, // Whether to show axis linearrow: true, // Whether to show arrowlineArrowOffset: 10, // Arrow offset lengthlineArrowSize: 30, // Arrow sizelineLineWidth: 10, // Axis line stroke widthlineStroke: '#666', // Axis line stroke colorlineOpacity: 0.9, // Axis line overall opacity},},});
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
tick | Whether to show ticks | boolean | true | |
tickFilter | Tick filtering | (datum, index, data)=>boolean | - | |
tickFormatter | Tick formatting, for custom tick styles, callback returns tick direction | DisplayObject | (datum, index, data, Vector)=> DisplayObject | - | |
tickDirection | Tick direction, positive for side axis direction (main axis clockwise 90°), negative for negative side axis | 'positive' | 'negative' | positive | |
tickLength | Tick length | number |(datum, index, data)=>number | 15 | |
tickStroke | Tick stroke color | string | (datum, index, data, Vector)=>string | - | |
tickStrokeOpacity | Tick stroke opacity | number | (datum, index, data, Vector)=>number | - | |
tickLineWidth | Tick stroke width | number | (datum, index, data, Vector)=>number | - | |
tickLineDash | Tick stroke dash configuration, first value is segment length, second is gap distance. Setting [0, 0] means no stroke. | [number,number] | (datum, index, data, Vector)=>[number,number] | - | |
tickOpacity | Tick overall opacity | number | (datum, index, data, Vector)=>number | - | |
tickShadowColor | Tick shadow color | string | (datum, index, data, Vector)=>string | - | |
tickShadowBlur | Tick shadow Gaussian blur coefficient | number | (datum, index, data, Vector)=>number | - | |
tickShadowOffsetX | Tick shadow horizontal offset | number | (datum, index, data, Vector)=>number | - | |
tickShadowOffsetY | Tick shadow vertical offset | number | (datum, index, data, Vector)=>number | - | |
tickCursor | Tick cursor style | string | (datum, index, data, Vector)=>string | default |
({// Configure axisaxis: {y: {tickLength: 20, // Set y-axis tick lengthtickFilter: (_, i) => i % 3 !== 0, // Filter y-axis ticks, show every 3rd ticktick: true, // Whether to show tickstickDirection: 'positive', // Tick directiontickStroke: '#333', // Tick stroke colortickStrokeOpacity: 0.8, // Tick stroke opacitytickLineWidth: 2, // Tick stroke widthtickLineDash: [2, 2], // Tick stroke dash configurationtickOpacity: 1, // Tick overall opacitytickShadowColor: 'rgba(0,0,0,0.2)', // Tick shadow colortickShadowBlur: 2, // Tick shadow Gaussian blur coefficienttickShadowOffsetX: 1, // Tick shadow horizontal offsettickShadowOffsetY: 1, // Tick shadow vertical offsettickCursor: 'crosshair', // Tick cursor style},x: {tick: true, // Whether to show tickstickLength: 15, // Tick lengthtickDirection: 'negative', // Tick directiontickStroke: '#666', // Tick stroke colortickLineWidth: 1, // Tick stroke widthtickOpacity: 0.9, // Tick overall opacitytickFilter: (_, i) => i % 2 === 0, // Filter ticks, show only even index ticks},},});
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
label | Whether to show tick labels | boolean | - | |
labelFontSize | Label font size | number | (datum, index, data)=>number | - | |
labelFontFamily | Label font family | string | (datum, index, data)=>string | - | |
labelFontWeight | Label font weight | number |(datum, index, data)=>number | - | |
labelLineHeight | Label line height | number | (datum, index, data)=>number | - | |
labelTextAlign | Label text horizontal alignment | 'center' | 'end' | 'left' | 'right' | 'start' | (datum, index, data)=>string | 'start' | |
labelTextBaseline | Label text vertical baseline | 'top' | 'middle' | 'bottom' | 'alphabetic' | 'hanging' | (datum, index, data)=>string | 'bottom' | |
labelAlign | Label alignment - 'horizontal' always horizontal - 'parallel' parallel to axis - 'perpendicular' perpendicular to axis | 'horizontal' | 'parallel' | 'perpendicular' | parallel | |
labelFilter | Label filtering | (datum, index, data)=> boolean | - | |
labelFormatter | Label formatting, accepts function or d3-format supported string | string | (datum, index, array) => string | - | |
transform | Label transform to avoid text overlap. Supports text ellipsis, overlap hiding, auto rotation | Transform[] | - | |
labelTransform | Label transform shortcuts for local coordinate system transforms including scale, translate, rotate, skew, matrix transforms, see transform | string | - | |
labelAutoHide | Auto hide overlapping labels, effective when size is set | boolean | HideOverlapCfg | - | |
labelAutoRotate | Auto rotate labels, effective when size is set | boolean | RotateOverlapCfg | - | |
labelAutoEllipsis | Auto ellipsis labels, effective when size is set | boolean | EllipsisOverlapCfg | - | |
labelAutoWrap | Auto wrap labels, effective when size is set | boolean | WrapOverlapCfg | - | |
labelDirection | Label position relative to axis line, refer to tickDirection | 'positive' | 'negative' | positive | |
labelSpacing | Spacing between label and its corresponding tick | number | 0 | |
labelFill | Label text fill color | string | (datum, index, data)=>string | - | |
labelFillOpacity | Label text fill opacity | number | (datum, index, data)=>number | - | |
labelStroke | Label text stroke color | string | (datum, index, data)=>string | - | |
labelStrokeOpacity | Label text stroke opacity | number | (datum, index, data)=>number | - | |
labelLineWidth | Label text stroke width | number |(datum, index, data)=>number | - | |
labelLineDash | Label text stroke dash configuration, first value is segment length, second is gap distance. Setting [0, 0] means no stroke. | [number,number] | (datum, index, data)=>[number, number] | - | |
labelOpacity | Label text overall opacity | number | (datum, index, data)=>number | - | |
labelShadowColor | Label text shadow color | string | (datum, index, data)=>string | - | |
labelShadowBlur | Label text shadow Gaussian blur coefficient | number | (datum, index, data)=>number | - | |
labelShadowOffsetX | Label text shadow horizontal offset | number | (datum, index, data)=>number | - | |
labelShadowOffsetY | Label text shadow vertical offset | number | (datum, index, data)=>number | - | |
labelCursor | Label text cursor style | string | (datum, index, data)=>string | default | |
labelDx | Label text horizontal offset | number | (datum, index, data)=>number | 0 | |
labelDy | Label text vertical offset | number | (datum, index, data)=>number | 0 |
The labelFormatter
visual channel is used to adjust label formatting.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({type: 'interval',width: 500,height: 300,data: [{ id: 1, month: '03', sales: 200 },{ id: 3, month: '04', sales: 300 },{ id: 4, month: '05', sales: 400 },{ id: 5, month: '06', sales: 500 },{ id: 6, month: '07', sales: 600 },{ id: 7, month: '08', sales: 700 },],encode: { x: 'month', y: 'sales', color: 'month' },axis: {y: {title: 'Sales',},x: {title: 'Month',labelFontSize: 12,labelFormatter: (d) => `2025-${d}`, // Label formatting},},});chart.render();
labelTransform
is a shortcut provided by G for local coordinate system transforms, consistent with CSS Transform.
The following example shows how to configure labelTransform
to rotate x-axis labels by 90 degrees.
({axis: {x: {title: 'X Axis Title',labelFontSize: 12,labelFormatter: (d) => `2025-${d}`,labelTransform: 'rotate(90)',},},});
To avoid label overlap or exceeding display range, the system provides multiple optimization methods including ellipsis, rotation, hiding, and wrapping. These features can be configured in two ways:
transform
array (multi-strategy combination)labelAutoXXX
series properties (single strategy shortcuts) Recommended
Both approaches have identical core functionality, differing only in use cases and configuration methods.
transform
array (multi-strategy combination)
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({type: 'interval',width: 500,height: 500,data: [{ id: 1, label: 'X Axis Label 1', value: 200 },{ id: 3, label: 'X Axis Label 2', value: 300 },{ id: 4, label: 'X Axis Label 3', value: 400 },{ id: 5, label: 'X Axis Label 4', value: 500 },{ id: 6, label: 'X Axis Label 5', value: 600 },{ id: 7, label: 'X Axis Label 6', value: 700 },{ id: 8, label: 'X Axis Label 999', value: 800 },],encode: { x: 'label', y: 'value' },axis: {y: {title: 'Y Axis Title',},x: {title: 'X Axis Title',labelFontSize: 12,labelFormatter: (d) => `2025-${d}`,transform: [// Ellipsis{type: 'ellipsis',suffix: '..', // Ellipsis suffix (default ...)minLength: 8, // No ellipsis if less than 8 charactersmaxLength: 12, // Force ellipsis if more than 12 characters},// Wrap{type: 'wrap',wordWrapWidth: 80, // Maximum line width 80pxmaxLines: 2, // Maximum 2 linesrecoverWhenFailed: true, // Recover to default if wrapping fails},// Rotate{type: 'rotate',optionalAngles: [0, 45, 90], // Try rotating 0°, 45°, 90°recoverWhenFailed: true, // Recover to default angle if rotation fails},// Hide{type: 'hide',keepHeader: true, // Keep first labelkeepTail: true, // Keep last label},],},},});chart.render();
- Using
labelAutoHide
,labelAutoRotate
,labelAutoEllipsis
,labelAutoWrap
properties (requiressize
setting)
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({type: 'interval',width: 500,height: 500,data: [{ id: 1, label: 'X Axis Label 1', value: 200 },{ id: 3, label: 'X Axis Label 2', value: 300 },{ id: 4, label: 'X Axis Label 3', value: 400 },{ id: 5, label: 'X Axis Label 4', value: 500 },{ id: 6, label: 'X Axis Label 5', value: 600 },{ id: 7, label: 'X Axis Label 6', value: 700 },{ id: 8, label: 'X Axis Label 999', value: 800 },],encode: { x: 'label', y: 'value' },axis: {y: {title: 'Y Axis Title',},x: {title: 'X Axis Title',labelFontSize: 12,labelFormatter: (d) => `2025-${d}`,size: 100, // Must set sizelabelAutoEllipsis: {suffix: '..',minLength: 8,maxLength: 12,},labelAutoWrap: {wordWrapWidth: 80,maxLines: 2,recoverWhenFailed: true,},labelAutoRotate: {optionalAngles: [0, 45, 90], // Try rotating 0°, 45°, 90°recoverWhenFailed: true, // Recover to default angle if rotation fails},labelAutoHide: {keepHeader: true, // Keep first labelkeepTail: true, // Keep last label},},},});chart.render();
export interface Transform {/** Extra margin when avoiding label overlap */margin?: number[];}export interface EllipsisOverlapCfg extends Transform {type: 'ellipsis';/** Ellipsis replacement character, default is ... */suffix?: string;/** No ellipsis if text is shorter than this length */minLength: string | number;/** Always ellipsis if text is shorter than this length */maxLength?: string | number;/** Step size for each ellipsis operation */step?: string | number;}export interface RotateOverlapCfg extends Transform {type: 'rotate';/** Optional rotation angle values */optionalAngles: number[];/** Whether to recover to default rotation angle when rotation cannot avoid overlap */recoverWhenFailed?: boolean;}export interface HideOverlapCfg extends Transform {type: 'hide';/** Ensure first label is not hidden */keepHeader?: boolean;/** Ensure last label is not hidden */keepTail?: boolean;}export interface WrapOverlapCfg extends Transform {type: 'wrap';/** Maximum width per line */wordWrapWidth?: number;/** Maximum number of lines */maxLines?: number;recoverWhenFailed?: boolean;}
Grid lines have different styles in different coordinate systems
Scenario | Style |
---|---|
Cartesian | |
Polar | |
Polar | |
Polar Radar |
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
grid | Whether to show grid lines | boolean | false | |
gridFilter | Grid line filtering | (datum, index, data)=> boolean | - | |
gridLength | Grid line length. Generally, user configuration is not needed. | number | (datum, index, data)=> number | 0 | |
gridAreaFill | Grid area fill color | string | string[] | (datum, index, data)=> string | - | |
gridStroke | Grid line stroke color | string | (datum, index, data)=> string | - | |
gridStrokeOpacity | Grid line stroke opacity | number | (datum, index, data)=> number | - | |
gridLineWidth | Grid line stroke width | number | (datum, index, data)=> number | - | |
gridLineDash | Grid line stroke dash configuration, first value is segment length, second is gap distance. Setting [0, 0] means no stroke. | [number,number] | (datum, index, data)=> [number,number] | - | |
gridOpacity | Grid line overall opacity | number | (datum, index, data)=> number | - | |
gridShadowColor | Grid line shadow color | string | (datum, index, data)=> string | - | |
gridShadowBlur | Grid line shadow Gaussian blur coefficient | number | (datum, index, data)=> number | - | |
gridShadowOffsetX | Grid line shadow horizontal offset | number | (datum, index, data)=> number | - | |
gridShadowOffsetY | Grid line shadow vertical offset | number | (datum, index, data)=> number | - | |
gridCursor | Grid line cursor style | string | (datum, index, data)=> string | default |
Supports setting animation effects for updates
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
animate | Whether to enable animation | boolean | EffectTiming | - |
EffectTiming supports the following configurable properties:
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
delay | Delay execution time (ms) | number | - | |
duration | Animation duration (ms) | number | - | |
easing | Animation easing function | Easing | - | |
endDelay | End delay execution time (ms) | number | - | |
fill | Animation display effect when not running | Fill | - |
The axis component itself has no specific event types.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({type: 'interval', // Set chart type to bar chartmarginTop: 40, // Set chart top margin in pixelsdata: [{ id: 1, label: 'X Axis Label 1', value: 200 },{ id: 3, label: 'X Axis Label 2', value: 300 },{ id: 4, label: 'X Axis Label 3', value: 400 },{ id: 5, label: 'X Axis Label 4', value: 500 },{ id: 6, label: 'X Axis Label 5', value: 600 },{ id: 7, label: 'X Axis Label 6', value: 700 },],// Set data encodingencode: { x: 'label', y: 'value' },axis: {// Configure x axisx: {position: 'bottom', // Set axis position// Axis title configurationtitle: 'X Axis Title', // Axis title contenttitleFontWeight: 500, // Title font weighttitleSpacing: 15, // Distance from title to axistitlePosition: 'bottom', // Title position relative to axistitleFontSize: 14, // Title font sizetitleFill: '#333', // Title fill color// Grid line configurationgrid: true, // Whether to show grid linesgridLineWidth: 2, // Grid line stroke widthgridStroke: '#f0f0f0', // Grid line stroke colorgridStrokeOpacity: 0.8, // Grid line stroke opacitygridLineDash: [3, 3], // Grid line stroke dash configurationgridOpacity: 0.9, // Grid line overall opacitygridAreaFill: ['#fafafa', '#ffffff'], // Grid area fill colorgridFilter: (_, i) => i % 2 === 0, // Grid line filtering// Axis line configurationline: true, // Whether to show axis linelineLineWidth: 5, // Axis line stroke widthlineStroke: '#f50', // Axis line stroke colorarrow: true, // Whether to show arrowlineArrowOffset: 8, // Arrow offset length// Axis tick configurationtick: true, // Whether to show tickstickLineWidth: 5, // Tick stroke widthtickLength: 10, // Tick lengthtickStroke: '#3366ff', // Tick stroke colortickDirection: 'positive', // Tick directiontickOpacity: 0.9, // Tick overall opacity// Axis label configurationlabel: true, // Whether to show tick labelslabelFontSize: 12, // Label font sizelabelFill: '#009900', // Label fill colorlabelFontWeight: 500, // Label font weightlabelFontFamily: 'Arial', // Label font familylabelTextAlign: 'center', // Label text horizontal alignmentlabelTextBaseline: 'middle', // Label text vertical baselinelabelAlign: 'horizontal', // Label alignmentlabelDirection: 'positive', // Label position relative to axis linelabelSpacing: 5, // Spacing between label and its corresponding ticklabelFillOpacity: 0.9, // Label fill opacitylabelStroke: '#ffffff', // Label stroke colorlabelStrokeOpacity: 0.5, // Label stroke opacitylabelLineWidth: 1, // Label stroke widthlabelOpacity: 1, // Label overall opacitylabelDx: 2, // Label horizontal offsetlabelDy: 0, // Label vertical offsetlabelCursor: 'pointer', // Label cursor style},// Configure y axisy: {position: 'left', // Set axis position// Axis title configurationtitle: 'Y Axis Title', // Axis title contenttitleFontWeight: 500, // Title font weighttitleSpacing: 20, // Distance from title to axistitlePosition: 'left', // Title position relative to axistitleFontSize: 14, // Title font sizetitleFill: '#333', // Title fill color// Grid line configurationgrid: true, // Whether to show grid linesgridLineWidth: 2, // Grid line stroke widthgridStroke: '#e6e6e6', // Grid line stroke colorgridStrokeOpacity: 0.7, // Grid line stroke opacitygridLineDash: [5, 5], // Grid line stroke dash configurationgridOpacity: 0.8, // Grid line overall opacity// Axis line configurationline: true, // Whether to show axis linelineLineWidth: 5, // Axis line stroke widthlineStroke: '#f50', // Axis line stroke colorarrow: false, // Whether to show arrowlineOpacity: 1, // Axis line overall opacity// Axis tick configurationtick: true, // Whether to show tickstickLineWidth: 5, // Tick stroke widthtickLength: 10, // Tick lengthtickStroke: '#3366ff', // Tick stroke colortickDirection: 'negative', // Tick directiontickStrokeOpacity: 0.8, // Tick stroke opacity// Axis label configurationlabel: true, // Whether to show tick labelslabelFontSize: 12, // Label font sizelabelFill: '#009900', // Label fill colorlabelFontWeight: 500, // Label font weightlabelFontFamily: 'Helvetica', // Label font familylabelTextAlign: 'right', // Label text horizontal alignmentlabelTextBaseline: 'middle', // Label text vertical baselinelabelAlign: 'perpendicular', // Label alignmentlabelSpacing: 8, // Spacing between label and its corresponding ticklabelLineHeight: 1.2, // Label line heightlabelFormatter: (d) => `${d}万`, // Label formatting},},});chart.render();
For more examples, please visit the Chart Examples - Axis page.