yyt
2024-06-26 0cceb649e1dc443c2a91d26d81eacb0867c96db3
提交 | 用户 | 时间
0cceb6 1 <template>
Y 2   <div :class="className" :style="{height:height,width:width}" />
3 </template>
4
5 <script>
6 import * as echarts from 'echarts'
7 require('echarts/theme/macarons') // echarts theme
8 import resize from './mixins/resize'
9 import { getOffLineNum } from "@/api/main/bs/orderScheduling/orderScheduling";
10
11 export default {
12   mixins: [resize],
13   props: {
14     className: {
15       type: String,
16       default: 'chart'
17     },
18     width: {
19       type: String,
20       default: '100%'
21     },
22     height: {
23       type: String,
24       default: '350px'
25     },
26     autoResize: {
27       type: Boolean,
28       default: true
29     },
30     chartData: {
31       type: Object,
32       required: true
33     }
34   },
35   data() {
36     return {
37       chart: null,
38       data: [],
39       legendTitle: [],
40     }
41   },
42   watch: {
43     chartData: {
44       deep: true,
45       handler(val) {
46         this.setOptions(val)
47       }
48     }
49   },
50   mounted() {
51     this.getData()
52
53   },
54   beforeDestroy() {
55     if (!this.chart) {
56       return
57     }
58     this.chart.dispose()
59     this.chart = null
60   },
61   methods: {
62     getData(){
63       getOffLineNum().then(res => {
64         if (res.code === 200){
65           this.data = res.rows
66           this.data.forEach(x => {
67             this.legendTitle.push(x.name)
68           })
69           this.$nextTick(() => {
70             this.initChart()
71           })
72         }
73       })
74     },
75     initChart() {
76       this.chart = echarts.init(this.$el, 'macarons')
77       this.setOptions(this.chartData)
78     },
79     setOptions({ expectedData, actualData } = {}) {
80       this.chart.setOption({
81         title: {
82           text: '小时产量对比', // 标题文本
83           left: 'left' // 标题位置
84         },
85         xAxis: {
86           data: ['8:00', '9:00', '10:00','11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00','21:00','22:00'],
87           boundaryGap: false,
88           axisTick: {
89             show: false
90           },
91           type: 'category',
92           axisLabel: {
93             interval: 0,
94             rotate: 45,
95           },
96         },
97         grid: {
98           left: 20,
99           right: 20,
100           bottom: 20,
101           top: 30,
102           containLabel: true
103         },
104         tooltip: {
105           trigger: 'axis',
106           axisPointer: {
107             type: 'cross'
108           },
109           padding: [5, 10]
110         },
111         yAxis: {
112           axisTick: {
113             show: false
114           },
115           min:0,
116           max: this.data.length === 0 ? 100 : null
117         },
118         legend: {
119           data: this.legendTitle
120         },
121         series: this.data
122       })
123     }
124   },
125
126 }
127 </script>