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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| <template>
| <div :class="className" :style="{ height: height, width: width }" />
| </template>
|
| <script>
| import * as echarts from 'echarts';
| import { defineComponent, shallowRef } from 'vue';
| import resize from '@/utils/resize';
|
| export default defineComponent({
| name: 'LineChart',
| mixins: [resize],
| props: {
| className: {
| type: String,
| default: 'chart'
| },
| width: {
| type: String,
| default: '100%'
| },
| height: {
| type: String,
| default: '100%'
| },
| autoResize: {
| type: Boolean,
| default: true
| },
| chartData: {
| type: Object,
| required: true
| }
| },
| data() {
| return {
| chart: null
| };
| },
| watch: {
| chartData: {
| deep: true,
| handler(val) {
| this.setOptions(val);
| }
| }
| },
| mounted() {
| this.$nextTick(() => {
| this.initChart();
| });
| },
| beforeUnmount() {
| if (!this.chart) {
| return;
| }
| this.chart.dispose();
| this.chart = null;
| },
| methods: {
| initChart() {
| this.chart = shallowRef(echarts.init(this.$el));
| this.setOptions(this.chartData);
| },
| setOptions() {
| this.chart.setOption({
| grid: {
| top: 20,
| right: 20,
| bottom: 20,
| left: 20,
| containLabel: true
| },
| xAxis: {
| type: 'category',
| boundaryGap: false,
| splitLine: {
| show: true,
| lineStyle: {
| width: 1
| }
| }
| },
| yAxis: {
| type: 'value',
| axisLine: {
| show: true
| },
| splitLine: {
| show: true,
| lineStyle: {
| width: 1,
| type: 'dashed'
| }
| }
| },
| series: [
| {
| type: 'line',
| smooth: 0.6,
| symbol: 'none',
| data: [
| ['2019-10-10', 2],
| ['2019-10-11', 5],
| ['2019-10-12', 7],
| ['2019-10-13', 5],
| ['2019-10-14', 2],
| ['2019-10-15', 3],
| ['2019-10-16', 4],
| ['2019-10-17', 3],
| ['2019-10-18', 1]
| ]
| }
| ]
| });
| }
| }
| });
| </script>
|
|