提交 | 用户 | 时间
|
fd2207
|
1 |
<template> |
懒 |
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' |
c6e069
|
9 |
import { getOffLineNum } from "@/api/main/bs/orderScheduling/orderScheduling"; |
fd2207
|
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 { |
c6e069
|
37 |
chart: null, |
W |
38 |
data: [], |
|
39 |
legendTitle: [], |
fd2207
|
40 |
} |
懒 |
41 |
}, |
|
42 |
watch: { |
|
43 |
chartData: { |
|
44 |
deep: true, |
|
45 |
handler(val) { |
|
46 |
this.setOptions(val) |
|
47 |
} |
|
48 |
} |
|
49 |
}, |
|
50 |
mounted() { |
c6e069
|
51 |
this.getData() |
W |
52 |
|
fd2207
|
53 |
}, |
懒 |
54 |
beforeDestroy() { |
|
55 |
if (!this.chart) { |
|
56 |
return |
|
57 |
} |
|
58 |
this.chart.dispose() |
|
59 |
this.chart = null |
|
60 |
}, |
|
61 |
methods: { |
c6e069
|
62 |
getData(){ |
W |
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 |
}, |
fd2207
|
75 |
initChart() { |
懒 |
76 |
this.chart = echarts.init(this.$el, 'macarons') |
|
77 |
this.setOptions(this.chartData) |
|
78 |
}, |
|
79 |
setOptions({ expectedData, actualData } = {}) { |
|
80 |
this.chart.setOption({ |
e211c9
|
81 |
title: { |
J |
82 |
text: '小时产量对比', // 标题文本 |
|
83 |
left: 'left' // 标题位置 |
|
84 |
}, |
fd2207
|
85 |
xAxis: { |
c6e069
|
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'], |
fd2207
|
87 |
boundaryGap: false, |
懒 |
88 |
axisTick: { |
|
89 |
show: false |
|
90 |
} |
|
91 |
}, |
|
92 |
grid: { |
|
93 |
left: 10, |
|
94 |
right: 10, |
|
95 |
bottom: 20, |
|
96 |
top: 30, |
|
97 |
containLabel: true |
|
98 |
}, |
|
99 |
tooltip: { |
|
100 |
trigger: 'axis', |
|
101 |
axisPointer: { |
|
102 |
type: 'cross' |
|
103 |
}, |
|
104 |
padding: [5, 10] |
|
105 |
}, |
|
106 |
yAxis: { |
|
107 |
axisTick: { |
|
108 |
show: false |
|
109 |
} |
|
110 |
}, |
|
111 |
legend: { |
c6e069
|
112 |
data: this.legendTitle |
fd2207
|
113 |
}, |
c6e069
|
114 |
series: this.data |
fd2207
|
115 |
}) |
懒 |
116 |
} |
c6e069
|
117 |
}, |
W |
118 |
|
fd2207
|
119 |
} |
懒 |
120 |
</script> |