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
| <template>
| <el-card shadow="hover" header="实时收入" v-loading="loading">
| <scEcharts ref="c1" height="300px" :option="option"></scEcharts>
| </el-card>
| </template>
|
| <script>
| import scEcharts from '/@/components/scEcharts/index.vue';
|
| export default {
| title: '实时收入',
| icon: 'ele-DataLine',
| description: 'Echarts组件演示',
| components: {
| scEcharts,
| },
| data() {
| return {
| loading: true,
| option: {},
| };
| },
| created() {
| var _this = this;
| setTimeout(function () {
| _this.loading = false;
| }, 500);
|
| var option = {
| tooltip: {
| trigger: 'axis',
| },
| xAxis: {
| boundaryGap: false,
| type: 'category',
| data: (function () {
| var now = new Date();
| var res = [];
| var len = 30;
| while (len--) {
| res.unshift(now.toLocaleTimeString().replace(/^\D*/, ''));
| now = new Date(now - 2000);
| }
| return res;
| })(),
| },
| yAxis: [
| {
| type: 'value',
| name: '价格',
| splitLine: {
| show: false,
| },
| },
| ],
| series: [
| {
| name: '收入',
| type: 'line',
| symbol: 'none',
| lineStyle: {
| width: 1,
| color: '#409EFF',
| },
| areaStyle: {
| opacity: 0.1,
| color: '#79bbff',
| },
| data: (function () {
| var res = [];
| var len = 30;
| while (len--) {
| res.push(Math.round(Math.random() * 0));
| }
| return res;
| })(),
| },
| ],
| };
| this.option = option;
| },
| mounted() {
| var _this = this;
| setInterval(function () {
| var o = _this.option;
|
| o.series[0].data.shift();
| o.series[0].data.push(Math.round(Math.random() * 100));
|
| o.xAxis.data.shift();
| o.xAxis.data.push(new Date().toLocaleTimeString().replace(/^\D*/, ''));
|
| //_this.$refs.c1.myChart.setOption(o)
| }, 2100);
| },
| };
| </script>
|
|