Horizontal.js
1.83 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
import echarts from 'echarts';
module.exports = {
name: 'echarts',
data() {
return {
chartDom: null,
data: {},
}
},
methods: {
init() {
//基于准备好的dom,初始化echarts实例
this.chartDom = echarts.init(document.getElementById('chartDom'));
return this;
},
update() {
if (this.chartDom === null) {
this.init();
}
this.chartDom.setOption({
title: {
text: 'Bar Chart',
subtext: '数据来自网络'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['2011年', '2012年']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
},
series: [{
name: '2011年',
type: 'bar',
data: [18203, 23489, 29034, 104970, 131744, 630230]
}, {
name: '2012年',
type: 'bar',
data: [19325, 23438, 31000, 121594, 134141, 681807]
}]
});
}
},
mounted: function() {
this.init()
.update(this.data);
}
}