Skip to content

Commit 4aa0ee6

Browse files
committed
docs(demo): 增加动态交互图的一级导航 demo
1 parent 50df3f7 commit 4aa0ee6

File tree

11 files changed

+108
-49
lines changed

11 files changed

+108
-49
lines changed

docs/api/plot-api.en.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Through this method, you can modify the data of the plot and re-render the plot
5555
- Gauge、Liquid, which accept the updated percent value
5656
- Dual Axes, which has its own data structure
5757
58+
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
59+
5860
### 5. changeSize
5961
6062
```sign

docs/api/plot-api.zh.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ plot.changeData(data: object[] | number);
5555
- 仪表盘、水波图 等指标类的,直接传入更新的 percent 数值
5656
- 双轴图等复合类图表,直接传入自己的 data 数据结构
5757
58+
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
59+
5860
### 5. changeSize
5961
6062
```sign

examples/area/basic/demo/basic.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@ import { Area } from '@antv/g2plot';
22

33
fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
44
.then((res) => res.json())
5-
.then((originalData) => {
6-
let cnt = 2;
5+
.then((data) => {
76
const area = new Area('container', {
8-
data: originalData.slice(0, cnt),
7+
data,
98
xField: 'timePeriod',
109
yField: 'value',
1110
xAxis: {
1211
range: [0, 1],
1312
},
1413
});
1514
area.render();
16-
17-
const interval = setInterval(() => {
18-
if (cnt === originalData.length) {
19-
clearInterval(interval);
20-
} else {
21-
cnt += 1;
22-
area.changeData(originalData.slice(0, cnt));
23-
}
24-
}, 400);
2515
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Area } from '@antv/g2plot';
2+
3+
fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
4+
.then((res) => res.json())
5+
.then((originalData) => {
6+
let cnt = 2;
7+
const area = new Area('container', {
8+
data: originalData.slice(0, cnt),
9+
xField: 'timePeriod',
10+
yField: 'value',
11+
xAxis: {
12+
range: [0, 1],
13+
},
14+
});
15+
area.render();
16+
17+
const interval = setInterval(() => {
18+
if (cnt === originalData.length) {
19+
clearInterval(interval);
20+
} else {
21+
cnt += 1;
22+
area.changeData(originalData.slice(0, cnt));
23+
}
24+
}, 400);
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Line } from '@antv/g2plot';
2+
3+
function getData() {
4+
// generate an array of random data
5+
const data = [];
6+
const time = new Date().getTime();
7+
8+
for (let i = -19; i <= 0; i += 1) {
9+
data.push({
10+
x: time + i * 1000,
11+
y: Math.random() + 0.2,
12+
});
13+
}
14+
return data;
15+
}
16+
17+
const line = new Line('container', {
18+
data: getData(),
19+
padding: 'auto',
20+
xField: 'x',
21+
yField: 'y',
22+
xAxis: {
23+
type: 'time',
24+
mask: 'HH:MM:ss',
25+
},
26+
smooth: true,
27+
point: {},
28+
});
29+
30+
line.render();
31+
32+
setInterval(() => {
33+
const x = new Date().getTime(), // current time
34+
y = Math.random() + 0.2;
35+
const newData = line.options.data.slice(1).concat({ x, y });
36+
line.changeData(newData);
37+
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"title": {
3+
"zh": "中文分类",
4+
"en": "Category"
5+
},
6+
"demos": [
7+
{
8+
"filename": "dynamic-spline.ts",
9+
"title": {
10+
"zh": "实时刷新的曲线图",
11+
"en": "Spline updating real-time"
12+
},
13+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/uShhKpuVTc/dongtaigengxinzhexiantushuju.gif"
14+
},
15+
{
16+
"filename": "dynamic-area.ts",
17+
"title": {
18+
"zh": "动态更新的面积图",
19+
"en": "Area updating with dynamic"
20+
},
21+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/ld0NQtdLO0/mianjitugengxinshuju-after.gif"
22+
}
23+
]
24+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: ChangeData
3+
order: 0
4+
---
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: 动态更新数据
3+
order: 0
4+
---

examples/line/basic/demo/dynamic-line.ts

-29
This file was deleted.

examples/line/basic/demo/meta.json

-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@
3636
},
3737
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*r8MPQ4n9CIQAAAAAAAAAAAAAARQnAQ"
3838
},
39-
{
40-
"filename": "dynamic-line.ts",
41-
"title": {
42-
"zh": "动态更新折线图",
43-
"en": "Line plot updated dynamic"
44-
},
45-
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/vOmMGBA1k6/dongtaigengxinzhexiantushuju2.gif"
46-
},
4739
{
4840
"filename": "line-with-data-marker.ts",
4941
"title": {

gatsby-config.js

+8
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ module.exports = {
205205
en: 'General Configuration',
206206
},
207207
},
208+
{
209+
slug: 'dynamic-plots',
210+
icon: 'other',
211+
title: {
212+
zh: '动态交互图',
213+
en: 'Dynamic Plots',
214+
},
215+
},
208216
{
209217
slug: 'plugin',
210218
icon: 'other',

0 commit comments

Comments
 (0)