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)

renderer

Previous
surface3D
Next
rough

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

G2 is built on top of AntV G for rendering, so it inherits G's rendering capabilities. Currently, it supports three major Web standards: Canvas, SVG, and WebGL, with Canvas renderer being the built-in default renderer for G2. For more renderers, see G documentation.

Getting Started

import { Chart } from '@antv/g2';
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
import { Renderer as SVGRenderer } from '@antv/g-svg';
import { Renderer as WebGLRenderer } from '@antv/g-webgl';
const chart = new Chart({
container: 'container',
// Or choose WebGLRenderer, defaults to CanvasRenderer if not specified.
renderer: new SVGRenderer(),
});

Of course, before using them, you need to install them first using npm, yarn, or other package managers. For the overall package size of G2, only the Canvas renderer is built-in. For specific examples, refer to Renderer.

Options

All G renderers are used with:

new Renderer({ /_ options _/ });

Let's introduce the configuration options for creating each of the three renderers.

Canvas Renderer

PropertyDescriptionTypeDefault
enableDirtyRectangleRenderingWhether to enable "dirty rectangle" renderingbooleantrue
enableDirtyRectangleRenderingDebugWhether to enable "dirty rectangle" rendering debug modebooleanfalse

SVG Renderer

PropertyDescriptionTypeDefault
outputSVGElementIdWhether to add id attribute when generating SVGElementbooleantrue

WebGL Renderer

PropertyDescriptionTypeDefault
targetsSelect rendering environment and auto-downgrade in orderstring[]['webgl2', 'webgl1']

UMD Usage

When you need to replace the built-in Canvas renderer, for example, switching to SVG, you need to include a specific version of the G2 UMD file.

Online Example

First, include the UMD versions of @antv/g and @antv/g-svg:

<script src="https://unpkg.com/@antv/g"></script>
<script src="https://unpkg.com/@antv/g-svg"></script>

Then include the G2 UMD version that excludes @antv/g and @antv/g-svg, which we call the lite version:

<script src="https://unpkg.com/@antv/[email protected]/dist/g2-lite.min.js"></script>

Find the Renderer in the namespace window.G.SVG and instantiate it:

const { Chart } = window.G2;
const chart = new Chart({
container: 'container',
renderer: new window.G.SVG.Renderer(), // Pass in SVG Renderer
});

The lite version is provided mainly for the following considerations:

  • After removing @antv/g and the built-in @antv/g-canvas renderer, it's convenient to replace other renderers on demand without redundant built-in renderers
  • When used with other packages that use @antv/g, you can share the same core and renderer code, saving overall package size, for example:
<script src="https://unpkg.com/@antv/g"></script>
<script src="https://unpkg.com/@antv/g-svg"></script>
<script src="https://unpkg.com/@antv/[email protected]/dist/g2-lite.min.js"></script>
<script src="https://unpkg.com/@antv/g6-lite"></script>