logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.5
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • G2's complete configuration system
    • Chart
      • Components of G2 Charts
      • Chart Lifecycle
    • 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)

dodgeX

Previous
diffY
Next
flexX

Resource

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

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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-Interactive solution
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

dodgeX is a grouping layout transform that enables chart elements to be grouped and displayed by series through generating and applying series channel values. The dodgeX transform works primarily through the following steps:

  1. Group data by grouping conditions (defaults to the x channel)
  2. Generate series channel values using the values from the color channel
  3. Adjust the coordinate positions of different series within the same group according to order and spacing, forming a side-by-side structure

Use Cases

The dodgeX transform is primarily used for scenarios where data within the same group needs to be arranged side by side by series on the coordinate system, to highlight data differences and distribution characteristics between different series.

For example, the following case shows the population distribution of different age groups across US states.

Before using the dodgeX transform: Data will be stacked together, making it difficult to clearly see comparisons between age groups.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval',
autoFit: true,
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
format: 'csv',
},
axis: { y: { labelFormatter: '~s' } },
encode: { x: 'state', y: 'population', color: 'age' },
transform: [
{ type: 'sortX', by: 'y', reverse: true, slice: 6 },
// Note: No dodgeX transform is used here
],
});
chart.render();

After using the dodgeX transform: Through the dodgeX transform, data from different age groups are displayed side by side within each state, making it easy to visually compare them.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval',
autoFit: true,
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
format: 'csv',
},
axis: { y: { labelFormatter: '~s' } },
encode: { x: 'state', y: 'population', color: 'age' },
transform: [
{ type: 'sortX', by: 'y', reverse: true, slice: 6 },
{ type: 'dodgeX' }, // Apply dodgeX transform to achieve side-by-side grouping effect
],
});
chart.render();

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
groupByChannel or channel combination for data groupingstring | string[]x
orderBySorting rule for elements within groupsTransformOrder() => null
reverseWhether to reverse the order of elements in groupsbooleanfalse
paddingSpacing between elements within groups (0 ~ 1)number0

groupBy

groupBy is used to specify the channel or channel combination for data grouping. By default, it groups by the x channel, but it can also be specified as other channels or combinations of multiple channels.

orderBy

orderBy is used to specify the sorting rule for elements within groups, supporting multiple sorting strategies:

type Primitive = number | string | boolean | Date;
type TransformOrder =
| 'value'
| 'sum'
| 'series'
| 'maxIndex'
| string[]
| null
| ((data: Record<string, Primitive>) => Primitive);

reverse

reverse is used to control whether to reverse the order of elements within groups. When set to true, elements within groups will be arranged in the opposite order to the default.

padding

padding is used to control the spacing between elements within groups, with a value range from 0 to 1. The larger the value, the greater the spacing between elements; when the value is 0, there is no spacing between elements.

Examples

The following examples demonstrate the functionality of various configuration options for the dodgeX transform. We can see the differences by comparing before and after the transformation:

Before transformation: Data from different departments will be stacked, making horizontal comparison difficult.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const data = [
{ Quarter: 'Q1', Department: 'Sales', Performance: 90, Year: '2024' },
{ Quarter: 'Q1', Department: 'Marketing', Performance: 80, Year: '2024' },
{ Quarter: 'Q1', Department: 'R&D', Performance: 70, Year: '2024' },
{ Quarter: 'Q2', Department: 'Sales', Performance: 90, Year: '2024' },
{ Quarter: 'Q2', Department: 'Marketing', Performance: 70, Year: '2024' },
{ Quarter: 'Q2', Department: 'R&D', Performance: 80, Year: '2024' },
{ Quarter: 'Q3', Department: 'Sales', Performance: 70, Year: '2024' },
{ Quarter: 'Q3', Department: 'Marketing', Performance: 80, Year: '2024' },
{ Quarter: 'Q3', Department: 'R&D', Performance: 90, Year: '2024' },
{ Quarter: 'Q4', Department: 'Sales', Performance: 80, Year: '2024' },
{ Quarter: 'Q4', Department: 'Marketing', Performance: 70, Year: '2024' },
{ Quarter: 'Q4', Department: 'R&D', Performance: 90, Year: '2024' },
];
chart.options({
type: 'interval',
autoFit: true,
data,
encode: {
x: 'Quarter',
y: 'Performance',
color: 'Department',
},
// Note: No transform is used here
});
chart.render();

After transformation: The effect after applying the dodgeX transform, demonstrating the functionality of various configuration options:

  • groupBy: Group and display department data by x channel (Quarter)
  • orderBy: Set to value to sort elements within groups by performance value
  • reverse: Set to true to arrange elements within groups from high to low performance values
  • padding: Set spacing between elements within groups to 0.1

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const data = [
{ Quarter: 'Q1', Department: 'Sales', Performance: 90, Year: '2024' },
{ Quarter: 'Q1', Department: 'Marketing', Performance: 80, Year: '2024' },
{ Quarter: 'Q1', Department: 'R&D', Performance: 70, Year: '2024' },
{ Quarter: 'Q2', Department: 'Sales', Performance: 90, Year: '2024' },
{ Quarter: 'Q2', Department: 'Marketing', Performance: 70, Year: '2024' },
{ Quarter: 'Q2', Department: 'R&D', Performance: 80, Year: '2024' },
{ Quarter: 'Q3', Department: 'Sales', Performance: 70, Year: '2024' },
{ Quarter: 'Q3', Department: 'Marketing', Performance: 80, Year: '2024' },
{ Quarter: 'Q3', Department: 'R&D', Performance: 90, Year: '2024' },
{ Quarter: 'Q4', Department: 'Sales', Performance: 80, Year: '2024' },
{ Quarter: 'Q4', Department: 'Marketing', Performance: 70, Year: '2024' },
{ Quarter: 'Q4', Department: 'R&D', Performance: 90, Year: '2024' },
];
chart.options({
type: 'interval',
autoFit: true,
data,
encode: {
x: 'Quarter',
y: 'Performance',
color: 'Department',
},
transform: [
{
type: 'dodgeX', // Apply dodgeX transform
groupBy: 'x',
orderBy: 'value',
reverse: true,
padding: 0.1,
},
],
});
chart.render();