提交 | 用户 | 时间
|
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: { |
04b8ef
|
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','23:00'], |
fd2207
|
87 |
boundaryGap: false, |
懒 |
88 |
axisTick: { |
|
89 |
show: false |
2720ac
|
90 |
}, |
W |
91 |
type: 'category', |
|
92 |
axisLabel: { |
|
93 |
interval: 0, |
|
94 |
rotate: 45, |
|
95 |
}, |
fd2207
|
96 |
}, |
懒 |
97 |
grid: { |
2720ac
|
98 |
left: 20, |
W |
99 |
right: 20, |
fd2207
|
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 |
2720ac
|
114 |
}, |
W |
115 |
min:0, |
|
116 |
max: this.data.length === 0 ? 100 : null |
fd2207
|
117 |
}, |
懒 |
118 |
legend: { |
c6e069
|
119 |
data: this.legendTitle |
fd2207
|
120 |
}, |
c6e069
|
121 |
series: this.data |
fd2207
|
122 |
}) |
懒 |
123 |
} |
c6e069
|
124 |
}, |
W |
125 |
|
fd2207
|
126 |
} |
懒 |
127 |
</script> |