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)

range

Previous
polygon
Next
rangeX

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

range is a tool used to define a rectangular area. The position and size of this rectangle can be determined by two sets of numbers: one for the horizontal direction (x1, x2) and another for the vertical direction (y1, y2). It is commonly used for drawing auxiliary background areas or marking certain regions.

  • Horizontal direction (x1, x2):

    • x1: Where the rectangle starts in the horizontal direction.
    • x2: Where the rectangle ends in the horizontal direction.
  • Vertical direction (y1, y2):

    • y1: Where the rectangle starts in the vertical direction.
    • y2: Where the rectangle ends in the vertical direction.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/0b37279d-1674-42b4-b285-29683747ad9a.json',
},
children: [
{ type: 'lineX', data: [0] },
{ type: 'lineY', data: [0] },
{
type: 'range',
// Area chart data
data: [
{ x: [-25, 0], y: [-30, 0], region: '1' },
{ x: [-25, 0], y: [0, 20], region: '2' },
{ x: [0, 5], y: [-30, 0], region: '2' },
{ x: [0, 5], y: [0, 20], region: '1' },
],
// Encoding rules, x and y correspond to fields in data, color corresponds to region field
encode: { x: 'x', y: 'y', color: 'region' },
scale: {
color: {
range: ['#d8d0c0', '#a3dda1'],
independent: true,
guide: null,
},
},
style: {
fillOpacity: 0.2,
},
},
{
type: 'point',
encode: {
x: 'change in female rate',
y: 'change in male rate',
size: 'pop',
color: 'continent',
shape: 'point',
},
scale: {
color: {
range: ['#ffd500', '#82cab2', '#193442', '#d18768', '#7e827a'],
},
x: { domain: [-25, 5] },
y: { domain: [-30, 20] },
size: { range: [4, 30] },
},
style: { stroke: '#bbb', fillOpacity: 0.8 },
axis: { x: { title: false }, y: { title: false } },
},
],
});
chart.render();

Configuration

PropertyDescriptionTypeDefaultRequired
encodeConfigure the visual channels of the range mark, including x, y, color, shape, etc., to specify the relationship between visual element properties and dataencode-✓
styleConfigure the graphic style of the range markstyle-

encode

Configure the visual channels of the range mark.

PropertyDescriptionTypeDefaultRequired
xBind the x property channel of the range mark, usually a time or ordinal field from datastring-✓
yBind the y property channel of the range mark, usually a numeric or array field from datastring-✓

For more encode configurations, you can check the Encode introduction page.

style

Configure the style of the range mark.

PropertyDescriptionTypeDefaultRequired
fillFill color of the graphicstring | Function<string>-
fillOpacityFill opacity of the graphicnumber | Function<number>-
strokeStroke of the graphicstring | Function<string>-
strokeOpacityStroke opacitynumber | Function<number>-
lineWidthWidth of the graphic strokenumber | Function<number>-
lineDashDashed stroke configuration. The first value is the length of each dash segment, the second value is the distance between segments. Setting lineDash to [0, 0] results in no stroke[number,number] | Function<[number, number]>-
opacityOverall opacity of the graphicnumber | Function<number>-
shadowColorShadow color of the graphicstring | Function<string>-
shadowBlurGaussian blur coefficient of the graphic shadownumber | Function<number>-
shadowOffsetXHorizontal distance of the shadow from the graphicnumber | Function<number>-
shadowOffsetYVertical distance of the shadow from the graphicnumber | Function<number>-
cursorMouse cursor style. Same as CSS cursor style, default 'default'string | Function<string>'default'

For more style configurations, you can check the Style introduction page.

Examples

For more examples, you can visit the Chart Examples - Data Annotation page.