Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@antv/g2

antvis705.3kMIT5.3.3TypeScript support: included

the Grammar of Graphics in Javascript

antv, g2, visualization, chart, grammar, graphics, interaction, animation

readme

English | 简体中文

G2: The Concise and Progressive Visualization Grammar

G2 is a visualization grammar for dashboard building, data exploration and storytelling.

Build Status Coverage Status npm Version npm Download npm License

examples

G2 is named after Leland Wilkinson’s book The Grammar of Graphics and was profoundly inspired by it in the very beginning. Here are some resources you can begin with:

  • Introduction - a brief overview and G2's motivations
  • Examples - a large number of demos to learn from and copy-paste
  • Tutorials - interactive case-driven guides of G2's core concepts
  • API Reference - complete documentation for all visualization components
  • Editor - an intelligent generation tool based on AntV. It utilizes AI to reduce the development cost of data visualization, and can quickly generate visual charts through natural language.

✨ Features

  • Progressive Usage - The main objective of G2 is to help you get meaningful visualizations quickly with concise declarations and it infers the rest. But you can configure much more for complex and advanced situations.
  • Declarative API - We employs a functional declarative API to specify chart options in a programmatic fashion, which contributes to better logic reuse and more flexible code organization.
  • High Extensibility - To satisfy specific needs, G2 provides a convenient and consistent mechanism to extend everything you can imagine, whether a scale, a transform, a mark, etc,. You can even customize a brand new visualization tool based on this mechanism.
  • Comprehensive Grammar - G2 rejects a chart typology in favor of marks, transforms, scales, coordinates, and compositions. In addition to static visual representations, it's possible to declare data-driven animations and apply well-designed action-based interactions to plots as well.
  • Powerful Renderer - There is a powerful renderer G under G2 to generate web-based visualizations using Canvas, SVG or WebGL. The plenty of plugins it has benefit G2 from rendering charts with novel styles such as hand-drawn and fully embracing the ecosystem of D3.

🔨 Getting Started

G2 is usually installed via a package manager such as npm or Yarn.

$ npm install @antv/g2
$ yarn add @antv/g2

The Chart object then can be imported from G2.

<div id="container"></div>
import { Chart } from '@antv/g2';

// A tabular data to be visualized.
const data = [
  { genre: 'Sports', sold: 275 },
  { genre: 'Strategy', sold: 115 },
  { genre: 'Action', sold: 120 },
  { genre: 'Shooter', sold: 350 },
  { genre: 'Other', sold: 150 },
];

// Instantiate a new chart.
const chart = new Chart({
  container: 'container',
});

// Specify visualization.
chart
  .interval() // Create an interval mark and add it to the chart.
  .data(data) // Bind data for this mark.
  .encode('x', 'genre') // Assign genre column to x position channel.
  .encode('y', 'sold') // Assign sold column to y position channel.
  .encode('color', 'genre'); // Assign genre column to color channel.

// Render visualization.
chart.render();

If all goes well, you can get the following lovely bar chart!

example

🌍 Ecosystem

📮 Contributing

code

📄 License

MIT@AntV.

changelog

5.3.3 (2025-05-20)

Bug Fixes

Features

5.3.2 (2025-04-21)

5.3.1 (2025-04-21)

Bug Fixes

  • docs: fix a render error of char '|' (#6785) (04dade0)
  • label: the labels in the treemap are blocking click interactions (#6765) (f99d0af)
  • tooltip pickup error when width is not equal (#6738) (1e73769)
  • tooltip with one element (#6763) (0318b9d)

Features

Reverts

5.3.0 (2025-04-10)

Bug Fixes

Features

5.2.12 (2025-03-17)

Bug Fixes

Features

  • add action to update documentations to yuque (#6627) (086b39e)
  • add support for multi-select hotkeys (#6628) (f0c21a1)
  • docs: update docs, image、linX、lineY、link、liquid、polygon (#6635) (a9c9ce9)

5.2.11 (2025-02-11)

Bug Fixes

Features

5.2.10 (2024-12-10)

Bug Fixes

  • site dev error & lodash ghost dependency (#6543) (71fd89d)

Features

  • add tooltip data to tooltip event callback (#6529) (c04318f)

5.2.9 (2024-12-06)

Bug Fixes

  • label: correct label selector parameter handling and test case (#6532) (f8ce4ee)
  • remove unnecessary structure and update label attributes (#6538) (9d66375)

Features

  • gauge: add custom text tooltip support for gauge chart (#6533) (9e57dfe)
  • label: implement label color inheritance from dependent elements (#6536) (56c0a3e)
  • transform: add exponential smoothing data transform methods (#6522) (0ec584c)

5.2.8 (2024-10-18)

Bug Fixes

5.2.7 (2024-10-08)

Bug Fixes

5.2.6 (2024-09-30)

Bug Fixes

  • update the position of lineXY with arrow (#6442) (3d426cc)
  • when update the position of tooltip, calculate the containerOffset (#6469) (ed5a1d6)
  • 订正slider组件属性文件 (#6467) (5c5f97a)

Features

  • add columnWidthRatio configuration to the style of the interval (#6474) (ff5bbc0)

5.2.5 (2024-08-30)

Bug Fixes

  • sankey tooltip interaction when type is view (#6417) (8e3538c)
  • the mouse position is offset of dodgeX tooltip event (#6418) (f003001)

5.2.4 (2024-08-26)

Bug Fixes

5.2.3 (2024-08-12)

Bug Fixes

  • tooltip: replaceChildren compatible with lower versions (#321)

Features

5.2.2 (2024-07-25)

Bug Fixes

Features

  • filter: add no selected elements display for itme-filter (#6374) (27dfc5e)
  • pie: optimize spider (#6357) (d07be48)
  • scale: add groupTransform for scales to support sync dual axes (#6380) (af17247)
  • tooltip: custom marker tooltip (#6384) (1d43dd4)

5.2.1 (2024-07-11)

Bug Fixes

  • dodgeX: do not update series channel if groupBy is invalid (#6344) (87c39da)
  • legend-filter: filter facet pie (#6346) (b7bb946)

Features

5.2.0 (2024-06-28)

Bug Fixes

Features

5.1.23 (2024-06-24)

Bug Fixes

Features

5.1.22 (2024-06-17)

Bug Fixes

  • tooltip: items for transposed interval + line (#6286) (65e09b0)

Features

  • tooltip: show tooltip for small interval (#6289) (e9ac6e0)

5.1.21 (2024-06-04)

Bug Fixes

Features

  • add channels to style and label callback (#6250) (3c003d0)
  • add context for customize label transform (#6222) (acc0fc0)
  • interaction.tooltip: add crosshairs, crosshairsX, crosshairsY setting (#6229) (0f7dc62)
  • label: add label transform feature exceedAdjust (#6209) (fefd4ea)

5.1.20 (2024-05-08)

Bug Fixes

Features

  • add context for customize label transform (#6222) (acc0fc0)
  • label: add label transform feature exceedAdjust (#6209) (fefd4ea)

5.1.19 (2024-04-19)

Features

5.1.18 (2024-04-08)

Features

5.1.17 (2024-03-21)

Bug Fixes

Features

  • interaction: add elementpointmove interaction (#6110) (e36ce30)

5.1.16 (2024-03-14)

Bug Fixes

Features

5.1.15 (2024-01-16)

Bug Fixes

  • api: auotFit sizeOf width > auto width > default width (#6013) (0f992d2)
  • api: scrollbar value 、silder values (#6033) (cded9ed)
  • fix point scale generates gradient color (#5977) (039716f)
  • slider: adjust tooltip's position when clipped (#6042) (c6a5ee4)

Features

5.1.14 (2024-01-05)

Bug Fixes

  • composition: fix composition lost chart value options (#5995) (7792a37)
  • wrong angles in polar coordinate (#6010) (ed5e780)

Features

5.1.13 (2023-12-21)

Bug Fixes

Features

  • transform: add pack padding and direction (#5964) (082606c)

5.1.12 (2023-12-12)

Bug Fixes

Features

  • rangeX and rangeY: add syntactic sugar for data (#5914) (1a28b3d)

5.1.11 (2023-12-06)

Bug Fixes

  • area and line shares the same curve generator(#5877) (b212242)
  • cannot find document if group destroyed (#5870) (c78da52)
  • ci and bench (#5880) (046ea5f)
  • fix the scaleInY animation(scale in the radial direction) on the polar coordinate (#5866) (5422bbb)
  • tooltip should account for container in string format (#5856) (d923eb9)
  • tooltip: wrong container (#5890) (9ed535a)

Features

5.1.10 (2023-11-28)

Bug Fixes

  • english title of site (#5840) (3d8a779)
  • fix subLayoutFacetCircle cal center y problem (#5833) (74ce08a)
  • fix the rendering issue caused by nodePaddingRatio in chord nodes using a hack method (#5824) (b0b37af)
  • interaction: reaapply some interactions when update (#5845) (54f4098)
  • tooltip: handle undefined (#5852) (3f3dda5)

5.1.9 (2023-11-22)

Bug Fixes

Features

5.1.8 (2023-11-14)

Bug Fixes

Features

5.1.8-beta.1 (2023-11-14)

Bug Fixes

Features

5.1.7 (2023-11-08)

Bug Fixes

5.1.6 (2023-10-20)

Bug Fixes

5.1.5 (2023-09-28)

Bug Fixes

Features

5.1.5-beta.0 (2023-09-25)

Bug Fixes

Features

5.1.4 (2023-09-20)

Bug Fixes

Features

5.1.3 (2023-09-18)

Bug Fixes

5.1.2 (2023-09-13)

Bug Fixes

Features

5.1.1 (2023-09-07)

Bug Fixes

Features

  • interaction: emit more brush and tooltip events (#5512) (57cc841)

5.1.0 (2023-08-31)

Bug Fixes

Features

5.0.24 (2023-08-30)

Bug Fixes

Features

5.0.23 (2023-08-29)

Bug Fixes

Features

5.0.22 (2023-08-24)

Bug Fixes

  • dep: add @antv/g-plugin-3d to dependencies (cb1c4b8)

5.0.21 (2023-08-23)

Bug Fixes

Features

5.0.20 (2023-08-17)

Bug Fixes

  • interaction: multi interaction (#5419) (328aeea)
  • types: add types for Chart interface (acd81b9)

5.0.19 (2023-08-15)

Bug Fixes

5.0.18 (2023-08-02)

Bug Fixes

Features

5.0.17 (2023-07-25)

Bug Fixes

Features

5.0.16 (2023-07-12)

Bug Fixes

5.0.15 (2023-07-07)

Bug Fixes

Features

5.0.14 (2023-06-28)

Bug Fixes

Features

5.0.13 (2023-06-20)

Bug Fixes

Features

5.0.12 (2023-06-08)

Bug Fixes

Features

5.0.11 (2023-05-26)

Bug Fixes

Features

5.0.10 (2023-05-25)

Bug Fixes

5.0.9 (2023-05-25)

Bug Fixes

Features

5.0.8 (2023-05-19)

Bug Fixes

  • brush: rerender don't emit brush:end (#5053) (f07b512)
  • brush: upper bound for selection (#5044) (b6ea831)
  • chart: chart.forceFit rerender only when size changing (#5052) (ab0ccf7)

Features

5.0.7 (2023-05-16)

Bug Fixes

Features

5.0.6 (2023-05-08)

Bug Fixes

Features

5.0.5 (2023-05-04)

Bug Fixes

  • axis: order of ticks for transposed x axis (#4918) (cf1cb88)
  • chart: autoFit do not set width and height of chart options (#4922) (f3632f5)
  • chart: new Chart() do not set default view key (#4925) (99538a6)
  • interaction: transpose sliderFilter (#4919) (6dc8e51)
  • transform: sort x only sort data in specified domain (#4932) (835933b)

Features

  • interaction: brushFilter emit filter event (#4933) (0e8f2d9)

5.0.4 (2023-04-25)

Bug Fixes

Features

5.0.3 (2023-04-12)

Bug Fixes

5.0.2 (2023-04-06)

Bug Fixes

5.0.1 (2023-03-29)

Bug Fixes

Features

  • ci: throw error in ci env for .only and missing snapshot (#4836) (a49f216)

5.0.0 (2023-03-21)

Release note.