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)

cell

Previous
boxplot
Next
chord

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

cell is an abstract representation of a rectangular mark (Rect Shape), primarily used to represent cells in facets or grids. It is the smallest unit for mapping data to visual elements in charts. Specifically, it is a type of area division that typically corresponds to an independent drawing area in different facets, commonly seen in matrix-type charts (such as calendar charts, aggregated heatmaps, etc.).

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'cell',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/seattle-weather.json',
},
transform: [{ type: 'group', color: 'max' }], // Apply group transformation to data, grouping by maximum color values
encode: {
x: (d) => new Date(d.date).getUTCDate(), // Encode x-axis using the UTC date part of the date field
y: (d) => new Date(d.date).getUTCMonth(), // Encode y-axis using the UTC month part of the date field
color: 'temp_max', // Encode color using the temp_max field from data
shape: 'cell',
},
style: { inset: 0.5 }, // Set cell inset to 0.5
scale: {
color: {
type: 'sequential', // Set color scale as sequential scale
palette: 'gnBu', // Use 'gnBu' color palette
},
},
});
chart.render(); // Render the chart

For more examples, please check the Chart Examples page.

Configuration

PropertyDescriptionTypeDefaultRequired
encodeConfigure visual channels for cell marks, including x, y, color, shape, etc., to specify the relationship between visual element properties and dataencode-✓
scaleConfigure graphic scaling for cell marks, including x, y, color, shape, etc.scale-
styleConfigure cell graphic stylesstyle-
transformConfigure cell data transformation operations (such as binning, sorting, filtering, etc.).transform-

encode

Configure visual channels for cell marks.

PropertyDescriptionTypeDefaultRequired
xBind the x property channel for cell marks, typically a time or ordered categorical field from dataencode-✓
yBind the y property channel for cell marks, typically a numerical or array field from dataencode-✓
colorBind the color property channel for cell marks; mapping data fields to color channels will group data, splitting data into multiple areas with different colorsencode-
shapeBind the shape property channel for cell marks, changing the drawing shape of graphic marks, supported properties: cell | hollowstringcell

For more encode configurations, please check the encode introduction page.

color

Through the color property in encode, you can map data fields to color values, automatically adjusting mark colors based on data changes. This is very useful for data visualization as it helps you quickly identify data patterns and trends.

(() => {
const chart = new G2.Chart();
chart.options({
type: 'cell',
data: [
{ x: 'x-a', y: 'y-a', data1: 1, data2: 5 },
{ x: 'x-a', y: 'y-b', data1: 3, data2: 8 },
{ x: 'x-a', y: 'y-c', data1: 2, data2: 6 },
{ x: 'x-b', y: 'y-a', data1: 8, data2: 2 },
{ x: 'x-b', y: 'y-b', data1: 5, data2: 4 },
{ x: 'x-b', y: 'y-c', data1: 6, data2: 9 },
{ x: 'x-c', y: 'y-a', data1: 7, data2: 1 },
{ x: 'x-c', y: 'y-b', data1: 4, data2: 2 },
{ x: 'x-c', y: 'y-c', data1: 9, data2: 3 },
],
encode: {
x: 'x', // Encode x-axis
y: 'y', // Encode y-axis
color: 'data1', // Use data1 field from data
},
style: {
inset: 5,
lineWidth: 10,
},
});
// Insert Encode-Color selector
const selectorContainer = document.createElement('div');
selectorContainer.textContent = 'Select field to map to color ';
const selector = document.createElement('select');
selector.innerHTML = `
<option value="data1" selected>data1</option>
<option value="data2">data2</option>
`;
selector.onchange = (e) => {
chart.options({
encode: {
color: e.target.value, // Map color using the selected field
},
});
chart.render(); // Re-render the chart
};
selectorContainer.appendChild(selector);
const node = chart.getContainer();
node.insertBefore(selectorContainer, node.childNodes[0]);
chart.render();
return node;
})();

shape

Through the shape property in encode, you can specify the geometric shape of cells. Shape determines how each cell is rendered on the canvas. The supported shapes for shape marks are as follows:

ShapeDescriptionExample
cellFill the entire cell with color
hollowDraw area chart with smooth curves

scale

scale is used to define how data maps to visual properties (such as color, size, shape, etc.). In cell usage scenarios, the common role of scale is to provide mapping rules for each visual channel (such as color, size, position, etc.), enabling data points to be accurately presented.

PropertyDescriptionTypeDefault
[channel]Channel mapped to visual propertyRecord<string, scale>-

For more scale configurations, please check the scale introduction page.

style

style is used to set the appearance styles of chart elements, including fill color, border styles, shadow effects, etc.

PropertyDescriptionTypeDefault
radiusBorder radius size for all four corners of the rectanglenumber | Function<number>0
radiusTopLeftTop-left corner radiusnumber | Function<number>0
radiusTopRightTop-right corner radiusnumber | Function<number>0
radiusBottomRightBottom-right corner radiusnumber | Function<number>0
radiusBottomLeftBottom-left corner radiusnumber | Function<number>0
insetInset padding for all four directions of the rectanglenumber | Function<number>0
insetLeftLeft inset paddingnumber | Function<number>0
insetRightRight inset paddingnumber | Function<number>0
insetBottomBottom inset paddingnumber | Function<number>0
insetTopTop inset paddingnumber | Function<number>0
fillFill color of the graphicstring | Function<string>Default is '' when shape is hollow
fillOpacityFill opacity of the graphicnumber | Function<number>Default is 0.95 when shape is cell
strokeStroke of the graphicstring | Function<string>-
strokeOpacityStroke opacitynumber | Function<number>Default is 1 when shape is hollow
lineWidthWidth of the graphic strokenumber | Function<number>Default is 2 when shape is hollow
lineDashDashed stroke configuration. First value is the length of each dash segment, 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 shadow from the graphicnumber | Function<number>-
shadowOffsetYVertical distance of shadow from the graphicnumber | Function<number>-
cursorMouse cursor style. Same as CSS cursor style, default 'default'.string | Function<string>'default'

For more style configurations, please check the style introduction page.

transform

transform is a core configuration item for data transformation, allowing preprocessing of raw data before binding it to graphic marks. By processing data, it generates more structured data suitable for visualization, thereby more clearly expressing data distribution, density, or statistical characteristics.

PropertyDescriptionTypeDefault
typeWhich channels to perform data grouping and aggregation onstring | string[]['x', 'y']
[channel]Aggregation method for data output to specific mark channelsReducer-
type Primitive = number | string | boolean | Date;
type Reducer =
| 'mean'
| 'max'
| 'count'
| 'min'
| 'median'
| 'sum'
| 'first'
| 'last'
| ((I: number[], V: Primitive[]) => Primitive);

For more transform configurations, please check the transform introduction page.

Try it out: