logo

G2

  • Docs
  • Chart Introduction
  • API
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Use In Framework
    • Experimental Spec 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
      • 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
      • pow
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
    • Transform
      • overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectX
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • overview
      • fisheye
      • parallel
      • polar
      • radial
      • theta
      • transpose
      • 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
      • fisheye
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
    • Composition
      • overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • overview
      • Academy
      • classic
      • classicDark
    • event
    • Color
  • Chart API
  • Chart Component
    • 标题(Title)
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • 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)

overview

Previous
Style
Next
fadeIn

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

Animate in G2 is an important part of visualization and can improve the expressiveness of visualization. Animate can be declared at the level of mark:

({
type: 'interval',
animate: {
enter: {
type: 'scaleInX',
duration: 100,
delay: 10,
},
update: {
type: 'morphing',
},
},
});
// API
// First way
chart
.interval()
.animate('enter', { type: 'scaleInX', duration: 100, delay: 10 })
.animate('update', { type: 'morphing' });
// Second way
chart.interval().animate({
enter: {
type: 'scaleInX',
duration: 100,
delay: 10,
},
update: {
type: 'morphing',
},
});

Animate Properties

Mark specifies animation properties through mark.animate, there are three parts of animation that can be specified:

  • enter- New graphics
  • update- Updated graphics
  • exit- deleted graphics

Each part of the animation has the following properties:

  • type
  • duration
  • delay
  • easing

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart
.interval()
.data([
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
])
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre')
.animate('enter', {
type: 'scaleInY', // Specify the type of entry animation
duration: 1000, // Specify the execution time of the entrance animation
});
chart.render();

Animation coding

Animation properties can be used as a channel in G2, and can also encode data. For example, in the gantt chart below, the appearance and duration of each bar are linearly related to the data.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart
.interval()
.coordinate({ transform: [{ type: 'transpose' }] })
.data([
{ name: 'event planning', startTime: 1, endTime: 4 },
{ name: 'layout logistics', startTime: 3, endTime: 13 },
{ name: 'select vendors', startTime: 5, endTime: 8 },
{ name: 'hire venue', startTime: 9, endTime: 13 },
{ name: 'hire caterer', startTime: 10, endTime: 14 },
{ name: 'hire event decorators', startTime: 12, endTime: 17 },
{ name: 'rehearsal', startTime: 14, endTime: 16 },
{ name: 'event celebration', startTime: 17, endTime: 18 },
])
.encode('x', 'name')
.encode('y', ['endTime', 'startTime'])
.encode('color', 'name')
.encode('enterDuration', (d) => d.endTime - d.startTime) // Calculate the duration and encode
.encode('enterDelay', 'startTime'); // Specify the time of occurrence and encode
chart.render();

Group animation

G2 also provides the StackEnter mark transform to implement group animation. This mark transform will first group graphics, and then stack their appearance time and duration in space to achieve the effect of appearing sequentially.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart
.interval()
.data([
{ type: 'Apple', year: '2001', value: 260 },
{ type: 'Orange', year: '2001', value: 100 },
{ type: 'Banana', year: '2001', value: 90 },
{ type: 'Apple', year: '2002', value: 210 },
{ type: 'Orange', year: '2002', value: 150 },
{ type: 'Banana', year: '2002', value: 30 },
])
//Group by color and appear in order
.transform({ type: 'stackEnter', groupBy: 'color' })
.encode('x', 'year')
.encode('y', 'value')
.encode('color', 'type')
.encode('series', 'type')
.encode('enterDuration', 1000); // The duration of each group is 1000
chart.render();

Keyframe Animation

The animations above are all excessive animations and do not involve data updates. G2 also provides the ability to create keyframe animations. use chart.timingKeyframe to create a time container that holds a series of views and applies smooth transitions to related graphical elements within those views. The corresponding relationship is specified by two channels, key and groupKey.

import { Chart } from '@antv/g2';
(async () => {
const data = await fetch(
'https://gw.alipayobjects.com/os/antvdemo/assets/data/scatter.json',
).then((res) => res.json());
const chart = new Chart({
container: 'container',
});
// Refer to the description of css animation
const keyframe = chart
.timingKeyframe() // Create container
.attr('iterationCount', 2) // Number of iterations
.attr('direction', 'alternate') // Direction
.attr('duration', 1000); // Duration
keyframe
.interval()
.transform({ type: 'groupX', y: 'mean' })
.data(data)
.encode('x', 'gender')
.encode('y', 'weight')
.encode('color', 'gender')
.encode('key', 'gender'); // Specify key
keyframe
.point()
.data(data)
.encode('x', 'height')
.encode('y', 'weight')
.encode('color', 'gender')
.encode('shape', 'point')
.encode('groupKey', 'gender'); // Specify groupKey
chart.render();

Time Series Animation

TimingSequence is still under development, please stay tuned.