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)

heatmap

Previous
gauge
Next
image

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

heatmap is a visualization chart that maps the density or value magnitude of two-dimensional data through color intensity, excelling at revealing data distribution patterns, clustering characteristics, and outliers. heatmap maps two categorical/continuous fields (such as x, y) to coordinate axis, and a third numerical field (such as value) to a color gradient (such as color: 'value'), forming a grid of colored blocks in a matrix. heatmap can define color scales, with cool colors (such as blue) representing low values and warm colors (such as red) representing high values, intuitively showing the magnitude or frequency distribution of values.

Typical applications include:

  • Correlation analysis: For example, used to display correlation matrices between variables, quickly identifying strongly correlated or weakly correlated variables through color intensity.
  • Density analysis: Display the density distribution of two-dimensional data, commonly used to observe hotspot areas, such as analyzing population clustering distribution in geospatial data.
  • Time series and category analysis: Combine time (such as hours, days, weeks) with categorical data to analyze temporal patterns or classification distributions.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'heatmap', // Mark type is heatmap
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/heatmap.json',
},
encode: { x: 'g', y: 'l', color: 'tmp' }, // Data encoding configuration, x-axis is 'g', y-axis is 'l', color is 'tmp'
style: { opacity: 0 }, // Heatmap opacity is 0
tooltip: false,
});
chart.render();

For more examples, you can check the Chart Examples - Heatmap page.

Options

PropertyDescriptionTypeDefaultRequired
encodeConfigure the visual channels of the heatmap mark, including x, y, color, etc., to specify the relationship between visual element properties and dataencode-✓
styleConfigure the heatmap graphics stylestyle-

encode

Configure the visual channels of the heatmap mark, defining the important configuration of the mapping relationship between data fields and visual properties, which determines how data is transformed into visual representation.

PropertyDescriptionTypeDefaultRequired
xBind the x property channel of the heatmap mark, generally a time or ordinal nominal field in dataencode-✓
yBind the y property channel of the heatmap mark, generally a numerical or array field in dataencode-✓
colorBind the color property channel of the heatmap mark. If a data field is mapped to the color channel, the data will be grouped and split into multiple areas of different colorsencode-

For more encode configuration, you can check the encode introduction page.

style

PropertyDescriptionTypeDefaultRequired
gradientGradient color configuration corresponding to the graphicsstring | Array<[number, string]>-
opacityTransparency of the heatmap. If set, it will override maxOpacity and minOpacity configuration, range 0 ~ 1number0.6
maxOpacityMaximum transparency value of heatmap pixels, effective when opacity = 0, range 0 ~ 1number1
minOpacityMinimum transparency value of heatmap pixels, effective when opacity = 0, range 0 ~ 1number0
blurBlur factor of the heatmap, range 0 ~ 1, the larger the value, the smoother the graphicsnumber0.85
useGradientOpacityFill color of the graphicsbooleanfalse
fillFill color of the graphicsstring | Function<string>-
fillOpacityFill transparency of the graphicsnumber | Function<number>-
strokeStroke of the graphicsstring | Function<string>-
strokeOpacityStroke transparencynumber | Function<number>-
lineWidthWidth of the graphics strokenumber | Function<number>-
lineDashDash configuration of the stroke. The first value is the length of each segment of the dash, and the second value is the distance between segments. Setting lineDash to [0, 0] results in no stroke.[number,number] | Function<[number, number]>-
shadowColorShadow color of the graphicsstring | Function<string>-
shadowBlurGaussian blur coefficient of the graphics shadownumber | Function<number>-
shadowOffsetXSet the horizontal distance of the shadow from the graphicsnumber | Function<number>-
shadowOffsetYSet the vertical distance of the shadow from the graphicsnumber | Function<number>-
cursorMouse style. Same as CSS mouse style, default 'default'.string | Function<string>'default'

Regarding the gradient configuration, here's an example, which is also the default built-in gradient color in G2:

const gradient = [
[0.25, 'rgb(0,0,255)'],
[0.55, 'rgb(0,255,0)'],
[0.85, 'yellow'],
[1.0, 'rgb(255,0,0)'],
];
const gradient =
'0.25:rgb(0,0,255) 0.55:rgb(0,255,0) 0.85:yellow 1.0:rgb(255,0,0)';

For more style configuration, you can check the style introduction page.

Give it a try:

Examples

  • You can create a container view to render both heatmap and map simultaneously, intuitively presenting data differences in geographical locations

const chart = new g2.Chart();
chart.options({
type: 'view',
autoFit: true,
padding: 0,
axis: false,
children: [
{
type: 'image',
style: {
src: 'https://gw.alipayobjects.com/zos/rmsportal/NeUTMwKtPcPxIFNTWZOZ.png',
x: '50%',
y: '50%',
width: '100%',
height: '100%',
},
tooltip: false,
},
{
type: 'heatmap',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/heatmap.json',
},
encode: { x: 'g', y: 'l', color: 'tmp' },
style: { opacity: 0 },
tooltip: false,
},
],
});
chart.render();