---
title: "HTML 标签"
language: "zh"
canonical: "https://g2.antv.antgroup.com/zh/examples/component/label/htmllabel/"
version: "5.4.8"
---

# HTML 标签

[运行示例](https://g2.antv.antgroup.com/zh/examples/component/label/htmllabel/)

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

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

## 源码

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

const chart = new Chart({
  container: 'container',
  autoFit: true,
});

const data = [
  { repo: 'G', star: 918 },
  { repo: 'G2', star: 11688 },
  { repo: 'G6', star: 10045 },
  { repo: 'L7', star: 3125 },
  { repo: 'F2', star: 7820 },
  { repo: 'S2', star: 1231 },
  { repo: 'X6', star: 4755 },
];

chart.options({
  type: 'interval',
  data: data,
  encode: { x: 'repo', y: 'star', color: 'repo' },
  labels: [
    {
      text: 'star',
      render: (text, datum) => {
        return `
        <div style="left:-50%;top:-20px;position:relative;font-size:14px;">
          <span>${datum.repo}</span>
          :
          <a href="https://github.com/antvis/${datum.repo}" target="_blank">${datum.star}</a>
        </div>
      `;
      },
    },
  ],
  legend: false,
});

chart.render();
```
