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
| <template>
| <div class="chart-wrap">
| <div ref="lineChart" class="line-chart"></div>
| </div>
| </template>
| <script>
| import * as echarts from 'echarts';
| import { smallLineOption } from '@/utils/chart/chart-option';
|
| export default {
| props: {
| modelValue: {
| type: Object
| // default: () => {
| // return {
| // xAxis: [],
| // series: []
| // };
| // }
| }
| },
| data() {
| return {
| option: null
| };
| },
| watch: {
| modelValue: {
| handler() {
| this.refreshChart();
| },
| deep: false,
| immediate: true
| }
| },
| methods: {
| refreshChart() {
| const { xAxis, series } = this.modelValue;
| if (!this.option) {
| this.option = smallLineOption(xAxis, series);
| } else {
| this.option.xAxis[0].data = xAxis;
| this.option.series = series;
| }
| if (this.lineChart) {
| this.lineChart.setOption(this.option, { notMerge: true });
| } else {
| this.onChartCreated = () => {
| this.lineChart.setOption(this.option, { notMerge: true });
| };
| }
| }
| },
| mounted() {
| this.lineChart = echarts.init(this.$refs.lineChart);
| if (typeof this.onChartCreated === 'function') {
| this.onChartCreated();
| }
| }
| };
| </script>
| <style scoped>
| .chart-wrap {
| /* width: 300px; */
| display: flex;
| justify-content: center;
| }
| .line-chart {
| width: 300px;
| height: 140px;
| /* border-bottom: 1px solid rgba(255, 255, 255, 0.329); */
| }
| </style>
|
|