bodyCenterRight.vue
1.79 KB
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
<template>
<div class="dv-content-body-center-list-right">
<div id="mind"></div>
</div>
</template>
<script>
export default {
data() {
return {
optionTwoLine: window.inventoryInformation_body2,
myChart: null,
}
},
methods: {
getData(data) {
const dom = document.getElementById('mind')
if (!dom) return
if (!this.myChart) {
this.myChart = this.$echarts.init(dom)
}
// if (!this.myChart) {
// this.myChart = this.$echarts.init(document.getElementById('mind')) // 或 'mind'
// }
if (!data || !Array.isArray(data)) return
const dates = data.map(item => item.day);
const quantities = data.map(item => item.count);
this.optionTwoLine.xAxis.data = this.monthDayDates(dates)
this.optionTwoLine.series[0].data = quantities
this.optionTwoLine.title.text = '出库趋势图'
this.optionTwoLine.series[0].lineStyle.color = 'red'
// myChart.clear()
this.myChart.setOption(this.optionTwoLine)
// window.addEventListener('resize', () => {
// myChart.resize();
// });
},
monthDayDates(data) {
return data.map(date => {
const [year, month, day] = date.split('-');
return `${month}-${day}`;
});
},
},
mounted() {
//this.getData()
//eslint-disable-next-line no-debugger
// debugger
this.resizeHandler = () => {
this.myChart && this.myChart.resize();
};
window.addEventListener('resize', this.resizeHandler);
},
beforeDestroy() {
// 移除事件监听
window.removeEventListener('resize', this.resizeHandler);
// 销毁 ECharts 实例
if (this.myChart) {
this.myChart.dispose();
this.myChart = null;
}
},
}
</script>
<style lang="less" scoped>
.dv-content-body-center-list-right {
width: 49%;
height: 95%;
border: 1.5px solid hsl(208.57deg 51.22% 40.2%);
}
#mind {
width: 100%;
height: 100%;
}
</style>