---
title: "量化热力图"
language: "zh"
canonical: "https://g2.antv.antgroup.com/zh/examples/general/cell/cell-quantize/"
version: "5.4.8"
---

# 量化热力图

[运行示例](https://g2.antv.antgroup.com/zh/examples/general/cell/cell-quantize/)

[资料索引](/llms.txt)

页面需要一个 `id="container"` 的 DOM 元素。以下为原始示例源码。

## 源码

```ts
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
  width: 900,
  height: 340,
});

chart.options({
  type: 'cell',
  data: {
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/89c20fe8-0c6f-46c8-b36b-4cb653dba8ed.json',
    transform: [{ type: 'map', callback: (d) => ({ salary: d }) }],
  },
  scale: { color: { type: 'quantize', range: ['#eee', 'pink', 'red'] } },
  legend: { color: { length: 400, labelFormatter: '.0s' } },
  encode: {
    y: (_, i) => (i % 5) + 1,
    x: (_, i) => ((i / 5) | 0) + 1,
    color: 'salary',
  },
  style: { stroke: '#000', inset: 2 },
  animate: { enter: { type: 'fadeIn' } },
});

chart.render();
```
