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)

area

Previous
Overview
Next
box

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

The area (area) graphic mark is mostly used to draw common area charts. It is a graphic that reflects numerical changes as ordered variables change, with principles similar to line. The characteristic of area charts is that the region between the polyline and the independent variable coordinate axis is filled with color or texture.

Additionally, in terms of data structure, the difference between area and line is that area can set an array of length 2 as the data for the y channel. The first and second elements of the array represent the upper and lower boundaries of the area chart respectively. This method is used to draw interval area charts. If not set, the default lower boundary is 0.

Area charts can also be used for comparing multiple series of data, expressing data totals and trends. Compared to line charts, area charts can not only clearly reflect data trend changes but also emphasize differences and comparisons between data of different categories.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/aapl.json',
},
// Configure visual channels
encode: {
x: (d) => new Date(d.date), // Configure x channel
y: 'close', // Configure y channel
shape: 'area', // Configure shape channel, can be omitted when default is 'area'. Options: 'area', 'smooth', 'hvh', 'vh', 'hv'
},
// Configure styles
style: {
fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff', // Configure area chart fill color as gradient
fillOpacity: 0.9, // Configure area mark fill opacity as 0.9
},
// Configure coordinate system
coordinate: {},
});
chart.render();

For more examples, check the Chart Examples - Area Charts page.

Configuration

PropertyDescriptionTypeDefault ValueRequired
encodeConfigure visual channels for area marks, including x, y, color, shape, etc., to specify relationships between visual elements and dataencode-✓
coordinateConfigure coordinate system for area marks. The coordinate system performs a series of point transformations to change the spatial display formcoordinate{type: 'cartesian' }
styleConfigure graphic styles for area marksstyle-

encode

Configure visual channels for area marks.

PropertyDescriptionTypeDefault ValueRequired
xBind the x property channel of area marks, usually a time or ordered categorical field in dataencode-✓
yBind the y property channel of area marks, usually a numerical or array field in dataencode-✓
colorBind the color property channel of area marks. If data fields are mapped to color channels, data will be grouped and split into multiple areas of different colors for stacked areasencode-
shapeBind the shape property channel of area marks to change the drawing shape of the graphic markarea | smooth | vh | hv | hvharea

x & y

The position visual channels of area marks require values from both x and y fields. The supported data formats are:

  • Both x and y are numerical values (categorical, continuous). Since area charts represent data trends, try to avoid having the field corresponding to the x axis be an unordered categorical type.
  • x is a numerical value (categorical, continuous), y is an array representing an interval value
x Channel Bindingy Channel BindingExplanation
NumericalNumericalRegular area chart
NumericalArrayStacked and interval area chart

color

The color visual channel affects the fill color of the enclosed area in area graphic marks. A single area in an area mark can only use one color (or gradient), but if data fields are mapped to color channels, the data will be grouped and split into multiple areas:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
data: [
{ country: 'Asia', year: '1750', value: 502 },
{ country: 'Asia', year: '1800', value: 635 },
{ country: 'Asia', year: '1850', value: 809 },
{ country: 'Asia', year: '1900', value: 947 },
{ country: 'Asia', year: '1950', value: 1402 },
{ country: 'Asia', year: '1999', value: 3634 },
{ country: 'Asia', year: '2050', value: 5268 },
{ country: 'Africa', year: '1750', value: 106 },
{ country: 'Africa', year: '1800', value: 107 },
{ country: 'Africa', year: '1850', value: 111 },
{ country: 'Africa', year: '1900', value: 133 },
{ country: 'Africa', year: '1950', value: 221 },
{ country: 'Africa', year: '1999', value: 767 },
{ country: 'Africa', year: '2050', value: 1766 },
{ country: 'Europe', year: '1750', value: 163 },
{ country: 'Europe', year: '1800', value: 203 },
{ country: 'Europe', year: '1850', value: 276 },
{ country: 'Europe', year: '1900', value: 408 },
{ country: 'Europe', year: '1950', value: 547 },
{ country: 'Europe', year: '1999', value: 729 },
{ country: 'Europe', year: '2050', value: 628 },
],
encode: {
x: 'year', // Configure x channel
y: 'value', // Configure y channel
color: 'country', // Configure color channel
},
style: { fillOpacity: 0.3 }, // Configure area mark fill opacity as 0.3
});
chart.render();

By configuring stackY in the transform, grouped areas can be stacked to form stacked area charts, avoiding information blur caused by overlapping:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
data: [
{ country: 'Asia', year: '1750', value: 502 },
{ country: 'Asia', year: '1800', value: 635 },
{ country: 'Asia', year: '1850', value: 809 },
{ country: 'Asia', year: '1900', value: 947 },
{ country: 'Asia', year: '1950', value: 1402 },
{ country: 'Asia', year: '1999', value: 3634 },
{ country: 'Asia', year: '2050', value: 5268 },
{ country: 'Africa', year: '1750', value: 106 },
{ country: 'Africa', year: '1800', value: 107 },
{ country: 'Africa', year: '1850', value: 111 },
{ country: 'Africa', year: '1900', value: 133 },
{ country: 'Africa', year: '1950', value: 221 },
{ country: 'Africa', year: '1999', value: 767 },
{ country: 'Africa', year: '2050', value: 1766 },
{ country: 'Europe', year: '1750', value: 163 },
{ country: 'Europe', year: '1800', value: 203 },
{ country: 'Europe', year: '1850', value: 276 },
{ country: 'Europe', year: '1900', value: 408 },
{ country: 'Europe', year: '1950', value: 547 },
{ country: 'Europe', year: '1999', value: 729 },
{ country: 'Europe', year: '2050', value: 628 },
],
encode: {
x: 'year', // Configure x channel
y: 'value', // Configure y channel
color: 'country', // Configure color channel
},
transform: [{ type: 'stackY' }], // Group by specified channels, stack y and y1 channels for each group to achieve stacking effect
style: { fillOpacity: 0.3 }, // Configure area mark fill opacity as 0.3
});
chart.render();

shape

The supported shapes for area marks are as follows:

ShapeDescriptionExample
areaDraw area chart with straight line connections
smoothDraw area chart with smooth curves
vhDraw step area chart, vertical then horizontal lines
hvDraw step area chart, horizontal then vertical lines
hvhDraw step area chart, vertical-horizontal-vertical, midpoint connection

coordinate

The display of area graphic marks differs under different coordinate systems. Depending on the coordinate system or coordinate system transformations, various charts such as area charts and radar charts can be drawn.

Coordinate System or TransformationCoordinate ConfigurationChart Type
Cartesian coordinate system{ type: 'cartesian' }Area charts etc
Polar coordinate system{ type: 'polar' }Radar charts etc

In polar coordinate systems, area charts need to be closed. Commonly used to draw radar charts.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
data: [
{ item: 'Design', type: 'a', score: 70 },
{ item: 'Design', type: 'b', score: 30 },
{ item: 'Development', type: 'a', score: 60 },
{ item: 'Development', type: 'b', score: 70 },
{ item: 'Marketing', type: 'a', score: 50 },
{ item: 'Marketing', type: 'b', score: 60 },
{ item: 'Users', type: 'a', score: 40 },
{ item: 'Users', type: 'b', score: 50 },
{ item: 'Test', type: 'a', score: 60 },
{ item: 'Test', type: 'b', score: 70 },
{ item: 'Language', type: 'a', score: 70 },
{ item: 'Language', type: 'b', score: 50 },
{ item: 'Technology', type: 'a', score: 50 },
{ item: 'Technology', type: 'b', score: 40 },
{ item: 'Support', type: 'a', score: 30 },
{ item: 'Support', type: 'b', score: 40 },
{ item: 'Sales', type: 'a', score: 60 },
{ item: 'Sales', type: 'b', score: 40 },
{ item: 'UX', type: 'a', score: 50 },
{ item: 'UX', type: 'b', score: 60 },
],
encode: { x: 'item', y: 'score', color: 'type' },
coordinate: { type: 'polar' }, // Configure coordinate system as polar for drawing radar charts
style: { fillOpacity: 0.5 },
axis: { x: { grid: true }, y: { zIndex: 1, title: false } }, // Configure chart components - coordinate axis
scale: { x: { padding: 0.5, align: 0 }, y: { tickCount: 5 } }, // Configure scales for better chart display
});
chart.render();

style

Configure styles for area marks.

PropertyDescriptionTypeDefault ValueRequired
connectWhether to connect null values with connector graphicsbooleanfalse
definedDetermines if data is a null value(d) => boolean(d) => !Number.isNaN(d) && d !== undefined && d !== null
connectFillconnector graphic fill colorstring | (d, index, data, column) => string-
connectFillOpacityconnector graphic fill opacitynumber | (d, index, data, column) => number-
connectStrokeconnector graphic strokestring | (d, index, data, column) => string-
connectStrokeOpacityconnector graphic stroke opacitynumber | (d, index, data, column) => number-
connectLineWidthconnector graphic stroke widthnumber | (d, index, data, column) => number-
connectLineDashconnector graphic stroke dash configuration. First value is dash segment length, second is gap distance. Setting lineDash to [0,0] results in no stroke[number,number] | (d, index, data, column) => [number, number]-
connectOpacityconnector graphic overall opacitynumber | (d, index, data, column) => number-
connectShadowColorconnector graphic shadow colorstring | (d, index, data, column) => string-
connectShadowBlurconnector graphic shadow Gaussian blur coefficientnumber | (d, index, data, column) => number-
connectShadowOffsetXHorizontal distance of shadow from connector graphicnumber | (d, index, data, column) => number-
connectShadowOffsetYVertical distance of shadow from connector graphicnumber | (d, index, data, column) => number-
connectCursorconnector graphic mouse cursor style. Same as CSS cursor stylestring | (d, index, data, column) => stringdefault
fillarea graphic fill colorstring | (d, index, data, column) => string-
fillOpacityarea graphic fill opacitynumber | (d, index, data, column) => number0.85
strokearea graphic strokestring | (d, index, data, column) => string-
strokeOpacityarea graphic stroke opacitynumber | (d, index, data, column) => number-
lineWidtharea graphic stroke widthnumber | (d, index, data, column) => number0
lineDasharea graphic stroke dash configuration. First value is dash segment length, second is gap distance. Setting lineDash to [0, 0] results in no stroke[number,number] | (d, index, data, column) => [number, number]-
opacityarea graphic overall opacitynumber | (d, index, data, column) => number-
shadowColorarea graphic shadow colorstring | (d, index, data, column) => string-
shadowBlurarea graphic shadow Gaussian blur coefficientnumber | (d, index, data, column) => number-
shadowOffsetXHorizontal distance of shadow from area graphicnumber | (d, index, data, column) => number-
shadowOffsetYVertical distance of shadow from area graphicnumber | (d, index, data, column) => number-
cursorarea graphic mouse cursor style. Same as CSS cursor stylestring | (d, index, data, column) => stringdefault

Try it out:

Examples

  • When using the connect feature, how to determine what kind of data is a null value?

You can use the defined configuration to determine whether it's a non-null value. By default, NaN, undefined, and null are null values. If you need data with value 0 to be treated as null for connection:

chart
.area()
// ...
.style('defined', (v) => v === 0);