-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.html
More file actions
105 lines (105 loc) · 2.38 KB
/
chart.html
File metadata and controls
105 lines (105 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,height=device-height">
<title>曲线折线图</title>
<style>::-webkit-scrollbar{display:none;}html,body{overflow:hidden;height:100%;margin:0;}</style>
</head>
<body>
<div id="mountNode"></div>
<script>/*Fixing iframe window.innerHeight 0 issue in Safari*/document.body.clientHeight;</script>
<script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g2-3.5.1/dist/g2.min.js"></script>
<script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.10.1/dist/data-set.min.js"></script>
<script>
// 在一行中保存多个城市的数据,需要将数据转换成
// {month: 'Jan', city: 'Tokyo', temperature: 3.9}
var data = [{
month: 'Jan',
Tokyo: 7.0,
London: 3.9
}, {
month: 'Feb',
Tokyo: 6.9,
London: 4.2
}, {
month: 'Mar',
Tokyo: 9.5,
London: 5.7
}, {
month: 'Apr',
Tokyo: 14.5,
London: 8.5
}, {
month: 'May',
Tokyo: 18.4,
London: 11.9
}, {
month: 'Jun',
Tokyo: 21.5,
London: 15.2
}, {
month: 'Jul',
Tokyo: 25.2,
London: 17.0
}, {
month: 'Aug',
Tokyo: 26.5,
London: 16.6
}, {
month: 'Sep',
Tokyo: 23.3,
London: 14.2
}, {
month: 'Oct',
Tokyo: 18.3,
London: 10.3
}, {
month: 'Nov',
Tokyo: 13.9,
London: 6.6
}, {
month: 'Dec',
Tokyo: 9.6,
London: 4.8
}];
var ds = new DataSet();
var dv = ds.createView().source(data);
// fold 方式完成了行列转换,如果不想使用 DataSet 直接手工转换数据即可
dv.transform({
type: 'fold',
fields: ['Tokyo', 'London'], // 展开字段集
key: 'city', // key字段
value: 'temperature' // value字段
});
var chart = new G2.Chart({
container: 'mountNode',
forceFit: true,
height: window.innerHeight
});
chart.source(dv, {
month: {
range: [0, 1]
}
});
chart.tooltip({
crosshairs: {
type: 'line'
}
});
chart.axis('temperature', {
label: {
formatter: function formatter(val) {
return val + '°C';
}
}
});
chart.line().position('month*temperature').color('city').shape('smooth');
chart.point().position('month*temperature').color('city').size(4).shape('circle').style({
stroke: '#fff',
lineWidth: 1
});
chart.render();
</script>
</body>
</html>