logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • Chart
      • Components of G2 Charts
      • How to Use Charts
    • Mark
      • Overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • point
      • polygon
      • range
      • rangeX
      • rangeY
      • rect
      • shape
      • text
      • vector
      • connector
      • wordCloud
    • View
    • Data
      • Overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy
    • Encode
    • Scale
      • Overview
      • band
      • linear
      • log
      • ordinal
      • point
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
      • pow
    • Transform
      • Overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectY
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • Overview
      • fisheye
      • parallel
      • polar
      • theta
      • transpose
      • radial
      • cartesian3D
      • helix
    • Style
    • Animate
      • Overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • State
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
      • fisheye
    • Composition
      • Overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • Overview
      • academy
      • classic
      • classicDark
    • Events
    • Color Mapping
  • Chart Component
    • Title
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Data Label
  • Extra Topics
    • Graph
      • forceGraph
      • pack
      • sankey
      • tree
      • treemap
    • Geo
      • geoPath
      • geoView
    • 3D
      • Draw 3D Chart
      • point3D
      • line3D
      • interval3D
      • surface3D
    • Plugin
      • renderer
      • rough
      • lottie
      • a11y
    • Package on demand
    • Set pattern
    • Server-Side Rendering (SSR)
    • Spec Function Expression Support (Available in 5.3.0)
  • Whats New
    • New Version Features
    • Migration from v4 to v5
  • Frequently Asked Questions (FAQ)

Axis

Previous
Title
Next
Legend

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

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."

Axis Usage Diagram

Components

Usage

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.

Enable Axis (enabled by default)

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 axis
axis: {
// Configure horizontal axis properties
x: {
// 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 axis
axis: {
// Configure vertical axis properties
y: {
// Configuration parameters and examples can be found below...
},
},
});

Configuration Levels

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

Hide axis for each channel:

Axis hiding demonstration

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,
});

Configuration Options

Each axis consists of title, line, tick, label, and grid.

PropertyDescriptionTypeDefault ValueRequired
titleSet axis title text and styletitle-
lineSet axis line display and styleline-
tickSet axis tick display and styletick-
labelSet axis label display and stylelabel-
gridSet axis grid display and stylegrid-
animateSet axis animation effectsboolean | animate-
positionSet axis positionleft | right | top | bottomx: bottom | y: left

Note

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
},
],
},
},
});

title

PropertyDescriptionTypeDefault ValueRequired
titleTurn off title or set title contentfalse|string | number | DisplayObject-
titleSpacingDistance from title to axisnumber | (datum, index, data) => number10
titlePositionTitle position relative to axis, supports abbreviation like 'top' as 't''top'|'bottom'|'left'|'right''lb'
titleFontSizeTitle font sizenumber | (datum, index, data) => number-
titleFontWeightTitle font weightnumber | (datum, index, data) => number-
titleFontFamilyTitle font familystring | (datum, index, data) => string-
titleLineHeightTitle line heightnumber | (datum, index, data) => number1
titleTextAlignTitle text horizontal alignment'center' | 'end' | 'left' | 'right' | 'start' | (datum, index, data) => string'start'
titleTextBaselineTitle text vertical baseline'top' | 'middle' | 'bottom' | 'alphabetic' | 'hanging' | (datum, index, data) => string'middle'
titleFillTitle text fill colorstring | (datum, index, data) => string-
titleFillOpacityTitle text fill opacitynumber | (datum, index, data) => number1
titleStrokeTitle text stroke colorstring | (datum, index, data) => stringtransparent
titleStrokeOpacityTitle text stroke opacitynumber | (datum, index, data) => number1
titleLineWidthTitle text stroke widthnumber | (datum, index, data) => number0
titleLineDashTitle text stroke dash configurationnumber[] | (datum, index, data) => number[][]
titleOpacityTitle text overall opacitynumber | (datum, index, data) => number1
titleShadowColorTitle text shadow colorstring | (datum, index, data) => stringtransparent
titleShadowBlurTitle text shadow Gaussian blur coefficientnumber | (datum, index, data) => number0
titleShadowOffsetXTitle text shadow horizontal offsetnumber | (datum, index, data) => number0
titleShadowOffsetYTitle text shadow vertical offsetnumber | (datum, index, data) => number0
titleCursorTitle text cursor stylestring | (datum, index, data) => stringdefault
titleDxTitle text horizontal offsetnumber | (datum, index, data) => number0
titleDyTitle text vertical offsetnumber | (datum, index, data) => number0

Configuration approach

({
// Configure axis
axis: {
// Configure y axis
y: {
// Axis title configuration
title: 'Frequency', // Set y-axis title
titleSpacing: 30, // Set spacing between y-axis title and axis line
titlePosition: 'left', // Set y-axis title position
titleFill: 'steelblue', // Set y-axis title color
titleFontSize: 16, // Set y-axis title font size
titleFontWeight: 'bold', // Set y-axis title font weight
titleFontFamily: 'Arial', // Set y-axis title font family
titleTextAlign: 'center', // Set y-axis title horizontal alignment
titleTextBaseline: 'middle', // Set y-axis title vertical baseline
titleOpacity: 0.9, // Set y-axis title overall opacity
titleStroke: '#333', // Set y-axis title stroke color
titleLineWidth: 1, // Set y-axis title stroke width
titleShadowColor: 'rgba(0,0,0,0.3)', // Set y-axis title shadow color
titleShadowBlur: 3, // Set y-axis title shadow blur
titleShadowOffsetX: 2, // Set y-axis title shadow horizontal offset
titleShadowOffsetY: 2, // Set y-axis title shadow vertical offset
titleDx: 5, // Set y-axis title horizontal offset
titleDy: 0, // Set y-axis title vertical offset
titleCursor: 'pointer', // Set y-axis title cursor style
},
// Configure x axis
x: {
// Axis title configuration
title: 'Letter', // Set x-axis title
titleSpacing: 20, // Set spacing between x-axis title and axis line
titlePosition: 'bottom', // Set x-axis title position
titleFontSize: 14, // Set x-axis title font size
titleFontWeight: 'normal', // Set x-axis title font weight
titleFill: '#666', // Set x-axis title color
titleTextAlign: 'center', // Set x-axis title horizontal alignment
titleOpacity: 1, // Set x-axis title opacity
titleLineHeight: 1.2, // Set x-axis title line height
titleFillOpacity: 0.8, // Set x-axis title fill opacity
},
},
});

line

PropertyDescriptionTypeDefault ValueRequired
lineWhether to show axis linebooleanfalse
arrowWhether to show arrowbooleantrue
lineExtensionExtension lines on both sides of axis[number, number]-
lineArrowDefine axis line arrow shape, defaults to arrow shapeDisplayObject-
lineArrowOffsetArrow offset lengthnumber15
lineArrowSizeArrow sizenumber-
lineStrokeAxis line stroke colorstring | (datum, index, data) => string-
lineStrokeOpacityAxis line stroke opacitynumber | (datum, index, data) => number-
lineLineWidthAxis line stroke widthnumber | (datum, index, data) => number-
lineLineDashAxis 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]-
lineOpacityAxis line overall opacitynumber | (datum, index, data) => number1
lineShadowColorAxis line shadow colorstring | (datum, index, data) => string-
lineShadowBlurAxis line shadow Gaussian blur coefficientnumber | (datum, index, data) => number-
lineShadowOffsetXAxis line shadow horizontal offsetnumber | (datum, index, data) => number-
lineShadowOffsetYAxis line shadow vertical offsetnumber | (datum, index, data) => number-
lineCursorAxis line cursor stylestring | (datum, index, data) => stringdefault

Configuration approach

({
axis: {
x: {
line: true, // Whether to show axis line
arrow: true, // Whether to show arrow
lineArrowOffset: 10, // Arrow offset length
lineArrowSize: 30, // Arrow size
lineLineWidth: 10, // Axis line stroke width
lineExtension: [5, 5], // Extension lines on both sides of axis
lineStroke: '#333', // Axis line stroke color
lineStrokeOpacity: 0.8, // Axis line stroke opacity
lineLineDash: [5, 5], // Axis line stroke dash configuration
lineOpacity: 1, // Axis line overall opacity
lineShadowColor: 'rgba(0,0,0,0.3)', // Axis line shadow color
lineShadowBlur: 3, // Axis line shadow Gaussian blur coefficient
lineShadowOffsetX: 2, // Axis line shadow horizontal offset
lineShadowOffsetY: 2, // Axis line shadow vertical offset
lineCursor: 'pointer', // Axis line cursor style
},
y: {
line: true, // Whether to show axis line
arrow: true, // Whether to show arrow
lineArrowOffset: 10, // Arrow offset length
lineArrowSize: 30, // Arrow size
lineLineWidth: 10, // Axis line stroke width
lineStroke: '#666', // Axis line stroke color
lineOpacity: 0.9, // Axis line overall opacity
},
},
});

tick

PropertyDescriptionTypeDefault ValueRequired
tickWhether to show ticksbooleantrue
tickFilterTick filtering(datum, index, data)=>boolean-
tickFormatterTick formatting, for custom tick styles, callback returns tick directionDisplayObject | (datum, index, data, Vector)=> DisplayObject-
tickDirectionTick direction, positive for side axis direction (main axis clockwise 90°), negative for negative side axis'positive' | 'negative'positive
tickLengthTick lengthnumber|(datum, index, data)=>number15
tickStrokeTick stroke colorstring | (datum, index, data, Vector)=>string-
tickStrokeOpacityTick stroke opacitynumber | (datum, index, data, Vector)=>number-
tickLineWidthTick stroke widthnumber | (datum, index, data, Vector)=>number-
tickLineDashTick 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]-
tickOpacityTick overall opacitynumber | (datum, index, data, Vector)=>number-
tickShadowColorTick shadow colorstring | (datum, index, data, Vector)=>string-
tickShadowBlurTick shadow Gaussian blur coefficientnumber | (datum, index, data, Vector)=>number-
tickShadowOffsetXTick shadow horizontal offsetnumber | (datum, index, data, Vector)=>number-
tickShadowOffsetYTick shadow vertical offsetnumber | (datum, index, data, Vector)=>number-
tickCursorTick cursor stylestring | (datum, index, data, Vector)=>stringdefault
({
// Configure axis
axis: {
y: {
tickLength: 20, // Set y-axis tick length
tickFilter: (_, i) => i % 3 !== 0, // Filter y-axis ticks, show every 3rd tick
tick: true, // Whether to show ticks
tickDirection: 'positive', // Tick direction
tickStroke: '#333', // Tick stroke color
tickStrokeOpacity: 0.8, // Tick stroke opacity
tickLineWidth: 2, // Tick stroke width
tickLineDash: [2, 2], // Tick stroke dash configuration
tickOpacity: 1, // Tick overall opacity
tickShadowColor: 'rgba(0,0,0,0.2)', // Tick shadow color
tickShadowBlur: 2, // Tick shadow Gaussian blur coefficient
tickShadowOffsetX: 1, // Tick shadow horizontal offset
tickShadowOffsetY: 1, // Tick shadow vertical offset
tickCursor: 'crosshair', // Tick cursor style
},
x: {
tick: true, // Whether to show ticks
tickLength: 15, // Tick length
tickDirection: 'negative', // Tick direction
tickStroke: '#666', // Tick stroke color
tickLineWidth: 1, // Tick stroke width
tickOpacity: 0.9, // Tick overall opacity
tickFilter: (_, i) => i % 2 === 0, // Filter ticks, show only even index ticks
},
},
});

label

PropertyDescriptionTypeDefault ValueRequired
labelWhether to show tick labelsboolean-
labelFontSizeLabel font sizenumber | (datum, index, data)=>number-
labelFontFamilyLabel font familystring | (datum, index, data)=>string-
labelFontWeightLabel font weightnumber |(datum, index, data)=>number-
labelLineHeightLabel line heightnumber | (datum, index, data)=>number-
labelTextAlignLabel text horizontal alignment'center' | 'end' | 'left' | 'right' | 'start' | (datum, index, data)=>string'start'
labelTextBaselineLabel text vertical baseline'top' | 'middle' | 'bottom' | 'alphabetic' | 'hanging' | (datum, index, data)=>string'bottom'
labelAlignLabel alignment
- 'horizontal' always horizontal
- 'parallel' parallel to axis
- 'perpendicular' perpendicular to axis
'horizontal' | 'parallel' | 'perpendicular'parallel
labelFilterLabel filtering(datum, index, data)=> boolean-
labelFormatterLabel formatting, accepts function or d3-format supported stringstring | (datum, index, array) => string-
transformLabel transform to avoid text overlap. Supports text ellipsis, overlap hiding, auto rotationTransform[]-
labelTransformLabel transform shortcuts for local coordinate system transforms including scale, translate, rotate, skew, matrix transforms, see transformstring-
labelAutoHideAuto hide overlapping labels, effective when size is setboolean | HideOverlapCfg-
labelAutoRotateAuto rotate labels, effective when size is setboolean | RotateOverlapCfg-
labelAutoEllipsisAuto ellipsis labels, effective when size is setboolean | EllipsisOverlapCfg-
labelAutoWrapAuto wrap labels, effective when size is setboolean | WrapOverlapCfg-
labelDirectionLabel position relative to axis line, refer to tickDirection'positive' | 'negative'positive
labelSpacingSpacing between label and its corresponding ticknumber0
labelFillLabel text fill colorstring | (datum, index, data)=>string-
labelFillOpacityLabel text fill opacitynumber | (datum, index, data)=>number-
labelStrokeLabel text stroke colorstring | (datum, index, data)=>string-
labelStrokeOpacityLabel text stroke opacitynumber | (datum, index, data)=>number-
labelLineWidthLabel text stroke widthnumber |(datum, index, data)=>number-
labelLineDashLabel 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]-
labelOpacityLabel text overall opacitynumber | (datum, index, data)=>number-
labelShadowColorLabel text shadow colorstring | (datum, index, data)=>string-
labelShadowBlurLabel text shadow Gaussian blur coefficientnumber | (datum, index, data)=>number-
labelShadowOffsetXLabel text shadow horizontal offsetnumber | (datum, index, data)=>number-
labelShadowOffsetYLabel text shadow vertical offsetnumber | (datum, index, data)=>number-
labelCursorLabel text cursor stylestring | (datum, index, data)=>stringdefault
labelDxLabel text horizontal offsetnumber | (datum, index, data)=>number0
labelDyLabel text vertical offsetnumber | (datum, index, data)=>number0

labelFormatter

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

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)',
},
},
});

transform

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:

  1. transform array (multi-strategy combination)
  2. labelAutoXXX series properties (single strategy shortcuts) Recommended

Both approaches have identical core functionality, differing only in use cases and configuration methods.

  1. 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 characters
maxLength: 12, // Force ellipsis if more than 12 characters
},
// Wrap
{
type: 'wrap',
wordWrapWidth: 80, // Maximum line width 80px
maxLines: 2, // Maximum 2 lines
recoverWhenFailed: 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 label
keepTail: true, // Keep last label
},
],
},
},
});
chart.render();
  1. Using labelAutoHide, labelAutoRotate, labelAutoEllipsis, labelAutoWrap properties (requires size 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 size
labelAutoEllipsis: {
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 label
keepTail: 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

Grid lines have different styles in different coordinate systems

ScenarioStyle
Cartesianlinear-grid
Polarcircle-grid
Polarpolar-grid
Polar Radarpolygon-grid
PropertyDescriptionTypeDefault ValueRequired
gridWhether to show grid linesbooleanfalse
gridFilterGrid line filtering(datum, index, data)=> boolean-
gridLengthGrid line length. Generally, user configuration is not needed.number | (datum, index, data)=> number0
gridAreaFillGrid area fill colorstring | string[]| (datum, index, data)=> string-
gridStrokeGrid line stroke colorstring | (datum, index, data)=> string-
gridStrokeOpacityGrid line stroke opacitynumber | (datum, index, data)=> number-
gridLineWidthGrid line stroke widthnumber | (datum, index, data)=> number-
gridLineDashGrid 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]-
gridOpacityGrid line overall opacitynumber | (datum, index, data)=> number-
gridShadowColorGrid line shadow colorstring | (datum, index, data)=> string-
gridShadowBlurGrid line shadow Gaussian blur coefficientnumber | (datum, index, data)=> number-
gridShadowOffsetXGrid line shadow horizontal offsetnumber | (datum, index, data)=> number-
gridShadowOffsetYGrid line shadow vertical offsetnumber | (datum, index, data)=> number-
gridCursorGrid line cursor stylestring | (datum, index, data)=> stringdefault

animate

Supports setting animation effects for updates

PropertyDescriptionTypeDefault ValueRequired
animateWhether to enable animationboolean | EffectTiming-

EffectTiming supports the following configurable properties:

PropertyDescriptionTypeDefault ValueRequired
delayDelay execution time (ms)number-
durationAnimation duration (ms)number-
easingAnimation easing functionEasing-
endDelayEnd delay execution time (ms)number-
fillAnimation display effect when not runningFill-

Events

The axis component itself has no specific event types.

Examples

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval', // Set chart type to bar chart
marginTop: 40, // Set chart top margin in pixels
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 },
],
// Set data encoding
encode: { x: 'label', y: 'value' },
axis: {
// Configure x axis
x: {
position: 'bottom', // Set axis position
// Axis title configuration
title: 'X Axis Title', // Axis title content
titleFontWeight: 500, // Title font weight
titleSpacing: 15, // Distance from title to axis
titlePosition: 'bottom', // Title position relative to axis
titleFontSize: 14, // Title font size
titleFill: '#333', // Title fill color
// Grid line configuration
grid: true, // Whether to show grid lines
gridLineWidth: 2, // Grid line stroke width
gridStroke: '#f0f0f0', // Grid line stroke color
gridStrokeOpacity: 0.8, // Grid line stroke opacity
gridLineDash: [3, 3], // Grid line stroke dash configuration
gridOpacity: 0.9, // Grid line overall opacity
gridAreaFill: ['#fafafa', '#ffffff'], // Grid area fill color
gridFilter: (_, i) => i % 2 === 0, // Grid line filtering
// Axis line configuration
line: true, // Whether to show axis line
lineLineWidth: 5, // Axis line stroke width
lineStroke: '#f50', // Axis line stroke color
arrow: true, // Whether to show arrow
lineArrowOffset: 8, // Arrow offset length
// Axis tick configuration
tick: true, // Whether to show ticks
tickLineWidth: 5, // Tick stroke width
tickLength: 10, // Tick length
tickStroke: '#3366ff', // Tick stroke color
tickDirection: 'positive', // Tick direction
tickOpacity: 0.9, // Tick overall opacity
// Axis label configuration
label: true, // Whether to show tick labels
labelFontSize: 12, // Label font size
labelFill: '#009900', // Label fill color
labelFontWeight: 500, // Label font weight
labelFontFamily: 'Arial', // Label font family
labelTextAlign: 'center', // Label text horizontal alignment
labelTextBaseline: 'middle', // Label text vertical baseline
labelAlign: 'horizontal', // Label alignment
labelDirection: 'positive', // Label position relative to axis line
labelSpacing: 5, // Spacing between label and its corresponding tick
labelFillOpacity: 0.9, // Label fill opacity
labelStroke: '#ffffff', // Label stroke color
labelStrokeOpacity: 0.5, // Label stroke opacity
labelLineWidth: 1, // Label stroke width
labelOpacity: 1, // Label overall opacity
labelDx: 2, // Label horizontal offset
labelDy: 0, // Label vertical offset
labelCursor: 'pointer', // Label cursor style
},
// Configure y axis
y: {
position: 'left', // Set axis position
// Axis title configuration
title: 'Y Axis Title', // Axis title content
titleFontWeight: 500, // Title font weight
titleSpacing: 20, // Distance from title to axis
titlePosition: 'left', // Title position relative to axis
titleFontSize: 14, // Title font size
titleFill: '#333', // Title fill color
// Grid line configuration
grid: true, // Whether to show grid lines
gridLineWidth: 2, // Grid line stroke width
gridStroke: '#e6e6e6', // Grid line stroke color
gridStrokeOpacity: 0.7, // Grid line stroke opacity
gridLineDash: [5, 5], // Grid line stroke dash configuration
gridOpacity: 0.8, // Grid line overall opacity
// Axis line configuration
line: true, // Whether to show axis line
lineLineWidth: 5, // Axis line stroke width
lineStroke: '#f50', // Axis line stroke color
arrow: false, // Whether to show arrow
lineOpacity: 1, // Axis line overall opacity
// Axis tick configuration
tick: true, // Whether to show ticks
tickLineWidth: 5, // Tick stroke width
tickLength: 10, // Tick length
tickStroke: '#3366ff', // Tick stroke color
tickDirection: 'negative', // Tick direction
tickStrokeOpacity: 0.8, // Tick stroke opacity
// Axis label configuration
label: true, // Whether to show tick labels
labelFontSize: 12, // Label font size
labelFill: '#009900', // Label fill color
labelFontWeight: 500, // Label font weight
labelFontFamily: 'Helvetica', // Label font family
labelTextAlign: 'right', // Label text horizontal alignment
labelTextBaseline: 'middle', // Label text vertical baseline
labelAlign: 'perpendicular', // Label alignment
labelSpacing: 8, // Spacing between label and its corresponding tick
labelLineHeight: 1.2, // Label line height
labelFormatter: (d) => `${d}万`, // Label formatting
},
},
});
chart.render();

For more examples, please visit the Chart Examples - Axis page.