-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmain.js
92 lines (80 loc) · 2.72 KB
/
main.js
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
import Vue from 'vue';
import V_Echarts from './directives/echarts';
const App = new Vue({
el: '#app',
data: {
barChartOptions: {
tooltip: {},
xAxis: {
data: ['A', 'B', 'C', 'D', 'E']
},
yAxis: {},
series: [
{
name: 'Num',
type: 'bar',
data: [5, 20, 36, 10, 10]
}
]
},
lineChartOptions: {
tooltip : {
trigger: 'axis'
},
xAxis : [
{
type : 'category',
boundaryGap : false,
data : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:'Num',
type:'line',
areaStyle: {normal: {}},
data: [52, 54, 60, 61, 65, 62, 80, 85, 90, 99, 40, 30, 20, 10, 0]
}
]
}
},
mounted: function () {
const _this = this;
// simulate realtime data change in line chart
setInterval(function () {
_this.updateLineChartData();
}, 1000);
// you can access an Echarts instance at the `mounted` stage of the parent VM,
// by accessing the `echartsInstance` property of the element
// that v-echarts directive is bind with
const barChartElement = document.querySelector('#this-is-bar-chart');
console.log(barChartElement.echartsInstance);
},
directives: {
'echarts': V_Echarts
},
methods: {
updateLineChartData: function () {
const _this = this;
// creat a fresh object with properties from the original object
const newLineChartOptions = Object.assign({}, _this.lineChartOptions);
// modify properties of the new object
// update xAxis data
newLineChartOptions.xAxis[0].data.push(
_this.lineChartOptions.xAxis[0].data[_this.lineChartOptions.xAxis[0].data.length - 1] + 1
);
newLineChartOptions.xAxis[0].data.shift();
// update series data
newLineChartOptions.series[0].data.push(Math.round(Math.random() * 100));
newLineChartOptions.series[0].data.shift();
// assign the new object to variable `lineChartOptions`, Vue.js will detect the change
// and Echarts will update the chart properly
_this.lineChartOptions = newLineChartOptions;
}
},
});