Default.js
2.26 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
import echarts from 'echarts';
module.exports = {
name: 'echarts',
data() {
return {
chartDom: null,
data: {
id: this.id,
title: this.title,
subtext: this.subtext,
hover_title: this.hoverTitle,
text_list: this.textList,
value_list: this.valueList
},
}
},
methods: {
init() {
//基于准备好的dom,初始化echarts实例
if (this.data.id) {
this.chartDom = echarts.init(document.getElementById(this.data.id));
}
return this;
},
update() {
if (this.chartDom === null) {
this.init();
}
if (this.chartDom) {
this.chartDom.setOption({
title: {
text: this.data.title,
subtext: this.data.subtext
},
tooltip: {},
xAxis: {
data: this.data.text_list
},
yAxis: {},
series: [{
name: this.data.hover_title,
type: 'bar',
data: this.data.value_list
}]
});
}
}
},
mounted: function() {
this.init()
.update(this.data);
},
props: {
id: [String],
title: [String, Number],
subtext: [String, Number],
hoverTitle: [String, Number],
textList: {
type: Array,
required: true
},
valueList: {
type: Array,
required: true
}
},
watch: {
valueList(v) {
this.data.value_list = v;
this.update();
},
textList(v) {
this.data.text_list = v;
this.update();
},
title(v) {
this.data.title = v;
this.update();
},
subtext(v) {
this.data.subtext = v;
this.update();
},
hoverTitle(v) {
this.data.hover_title = v;
this.update();
}
}
}