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
| <template>
| <div ref="myChart" style="width: 100%; height: 100%;"></div>
| </template>
|
| <script>
| import * as echarts from 'echarts'
|
| export default {
| props: {
| yAxisMonth: {
| type: Array,
| default: []
| },
| seriesData: {
| type: Array,
| default: []
| },
| otherData: {
| type: Object,
| default: {}
| }
| },
| data() {
| return {
| option: {
| title: {
| left: '5%',
| text: '设备名称:' + this.otherData.deviceName
| },
| toolbox: {
| right: '5%',
| feature: {
| dataZoom: {
| yAxisIndex: 'none'
| },
| restore: {},
| saveAsImage: {}
| }
| },
| grid: {
| right: '5%'
| },
| xAxis: {
| type: 'category',
| boundaryGap: false,
| data: this.yAxisMonth
| },
| yAxis: {
| type: 'value',
| boundaryGap: [0, '100%']
| },
| tooltip: {
| trigger: 'axis',
| formatter: (params) => {
| var tips = ''
| const value = params[0].value
| if (value) {
| tips =
| '编号:' +
| this.otherData.dataStream +
| '<br />参数:' +
| value +
| '<br />备注:' +
| (this.otherData.remark ? this.otherData.remark : '') +
| '<br />单位:' +
| (this.otherData.unit ? this.otherData.unit : '') +
| '<br />时间:' +
| params[0].axisValue
| }
| return tips
| }
| },
| series: [
| {
| // name: '参数',
| type: 'line',
| label: {
| normal: {
| show: true,
| position: 'top'
| }
| },
| symbol: 'none',
| areaStyle: { normal: {} },
| data: this.seriesData
| }
| ]
| }
| }
| },
| mounted() {
| // 正确使用 this 来定义 myChart 为组件实例的变量
| this.myChart = echarts.init(this.$refs.myChart)
| this.initDrag()
| },
| methods: {
| initDrag() {
| this.myChart.setOption(this.option)
|
| // 页面发生变化 tree 也改变
| window.addEventListener('resize', () => {
| if (this.myChart) this.myChart.resize()
| })
| },
| refreshData(seriesData, xAxisData) {
| // 刷新数据
| const refreshOption = this.myChart.getOption()
| refreshOption.series[0].data = seriesData
| refreshOption.xAxis[0].data = xAxisData
| // 使用 Promise 包装 setOption 使其成为异步操作
| this.myChart.setOption(refreshOption, true)
| }
| }
| }
| </script>
|
| <style lang="scss" scoped></style>
|
|