---
title: "图表模式"
language: "zh"
canonical: "https://g6.antv.antgroup.com/zh/examples/plugin/timebar/chart/"
version: "5.1.1"
---

# 图表模式

[运行示例](https://g6.antv.antgroup.com/zh/examples/plugin/timebar/chart/)

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

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

## 源码

```js
import { Graph } from '@antv/g6';

const startTime = new Date('2023-08-01').getTime();
const diff = 3600 * 24 * 1000;
const timebarData = [10, 2, 3, 4, 15, 10, 5, 0, 3, 1].map((value, index) => ({
  time: new Date(startTime + index * diff),
  value,
  label: new Date(startTime + index * diff).toLocaleString(),
}));
const graphData = {
  nodes: new Array(49).fill(0).map((_, index) => ({
    id: `node-${index}`,
    data: {
      timestamp: startTime + (index % 10) * diff,
      value: index % 20,
      label: new Date(startTime + (index % 10) * diff).toLocaleString(),
    },
  })),
  edges: new Array(49).fill(0).map((_, i) => ({
    id: `edge-${i}`,
    source: `node-${i % 30}`,
    target: `node-${(i % 20) + 29}`,
    data: {
      edgeType: 'e1',
    },
  })),
};

const graph = new Graph({
  container: 'container',
  data: graphData,
  behaviors: ['drag-canvas', 'drag-element', 'zoom-canvas'],
  layout: {
    type: 'grid',
    cols: 7,
  },
  plugins: [
    {
      type: 'timebar',
      key: 'timebar',
      data: timebarData,
      width: 450,
      height: 100,
      loop: true,
      timebarType: 'chart',
    },
  ],
  autoFit: 'view',
  padding: [10, 0, 160, 0],
});

graph.render();
```
