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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
| <template>
| <div class="bar-chart">
| <ChartTitle name="车间正品率"></ChartTitle>
| <div class="bar-contents">
| <div class="bar-total">
| <div class="bar-item">当日合计生产:{{ chartData.total }}</div>
| <div class="bar-item">正品率:{{ chartData.rate }}</div>
| </div>
| <div class="chart" ref="chart"></div>
| </div>
| </div>
| </template>
|
| <script>
| import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
| //引入echart
| import * as echarts from "echarts";
| let myChart;
| export default {
| components: {
| ChartTitle,
| },
| props: {
| chartData: {
| type: Object,
| require: true,
| default: () => {
| return {
| total: 0,
| rate: "0",
| datax: [],
| datay: [],
| datay2: [],
| };
| },
| },
| },
| data() {
| return {
| // chartData: {
| // total: 1000,
| // rate: "99%",
| // datax: [
| // "第一车间",
| // "第二车间",
| // "第三车间",
| // "第四车间",
| // "第五车间",
| // "第六车间",
| // "第七车间",
| // "第八车间",
| // "第九车间",
| // ],
| // datay: [120, 200, 150, 180, 170, 150, 130, 180, 140],
| // datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40],
| // },
| chartTimer: null,
| };
| },
| watch: {
| "chartData.datay"(val) {
| this.pieChart("chart", this.chartData);
| },
| },
| mounted() {
| // this.pieChart("chart", this.chartData);
| },
| methods: {
| //在职
| pieChart(chartName, data) {
| let that = this;
| clearInterval(this.chartTimer);
| let chartDom = this.$refs[chartName];
| if (myChart != null && myChart != "" && myChart != undefined) {
| myChart.dispose(); //销毁
| }
| myChart = echarts.init(chartDom);
| let option;
| let lineColor = "#35ddc74d";
| if (data) {
| option = {
| color: ["#dcb018", "#00FFFF"],
| tooltip: {
| trigger: "axis",
| axisPointer: {
| type: "none",
| },
| textStyle: {
| color: "#00FFFF",
| },
| borderColor: "#00FFFF",
| backgroundColor: "#238d8d6b",
| formatter: function (a) {
| let list = [];
| let listItem = "";
| let firstString =
| '<span style=width:70px;display:inline-block">' +
| "生产总数" +
| "</span> " +
| data.total;
| list.push(firstString);
| for (let i in a) {
| let str =
| '<span style=width:70px;display:inline-block">' +
| a[i].seriesName +
| "</span> " +
| a[i].value;
|
| list.push(str);
| }
| let lastString =
| '<span style=width:70px;display:inline-block">' +
| "正品率" +
| "</span> " +
| data.rate;
| list.push(lastString);
| listItem = list.join("<br>");
| return '<div class="showBox">' + listItem + "</div>";
| },
| },
| grid: {
| right: "10px",
| bottom: "60px",
| left: "10px",
| top: "10px",
| },
| dataZoom: [
| {
| type: "inside",
| xAxisIndex: 0,
| show: false,
| startValue: 0, // 从头开始
| endValue: 5, // 一次性展示几个
| },
| ],
| legend: {
| itemWidth: 8,
| itemHeight: 8,
| itemGap: 35, //间距
| bottom: "5px",
| left: "center",
| data: [
| {
| name: "正品数量",
| icon: "circle",
| textStyle: {
| color: "#dcb018",
| },
| },
| {
| name: "次品数量",
| icon: "circle",
| textStyle: {
| color: "#00FFFF",
| },
| },
| ],
| },
| xAxis: [
| {
| type: "category",
| axisTick: {
| show: false,
| },
| axisLine: {
| show: true,
| lineStyle: {
| color: lineColor,
| },
| },
| axisLabel: {
| margin: 10,
| show: true,
| textStyle: {
| color: "#00FFFF",
| },
| formatter: function (value) {
| if (value.length > 5) {
| return `${value.slice(0, 4)}...`;
| }
| return value;
| },
| },
| data: data.datax ? data.datax : [],
| },
| ],
| yAxis: [
| {
| type: "value",
| name: "",
| minInterval: 1, //坐标轴是整数
| max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //数据最大值加3
| interval:
| (Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5) / 5,
| position: "left",
| axisLine: {
| show: true,
| lineStyle: {
| color: lineColor,
| },
| },
| nameTextStyle: {
| color: "#00FFFF",
| },
| splitLine: {
| show: true,
| lineStyle: {
| // 使用深浅的间隔色
| color: lineColor,
| },
| },
| axisTick: {
| show: false,
| },
| axisLabel: {
| textStyle: {
| color: "#9B9B9B",
| },
| formatter: "",
| },
| },
| {
| type: "value",
| name: "",
| // min: data.yAxis[0].min?data.yAxis.min:0,
| minInterval: 1, //坐标轴是整数
| max: Math.ceil(eval(`Math.max(${data.datay2})`) / 5) * 5, //数据最大值加3
| interval:
| (Math.ceil(eval(`Math.max(${data.datay2})`) / 5) * 5) / 5,
| position: "right",
| axisLine: {
| show: true,
| lineStyle: {
| color: lineColor,
| },
| },
| nameTextStyle: {
| color: "#00FFFF",
| },
| splitLine: {
| show: true,
| lineStyle: {
| // 使用深浅的间隔色
| color: lineColor,
| },
| },
| axisTick: {
| show: false,
| },
| axisLabel: {
| textStyle: {
| color: "#9B9B9B",
| },
| formatter: "",
| },
| },
| ],
| series: [
| {
| type: "bar",
| name: "正品数量",
| barWidth: "15",
| itemStyle: {
| normal: {
| //柱形图圆角,初始化效果
| barBorderRadius: [4, 4, 0, 0],
| },
| },
| data: data.datay,
| },
| {
| type: "bar",
| name: "次品数量",
| barWidth: "15",
| itemStyle: {
| normal: {
| //柱形图圆角,初始化效果
| barBorderRadius: [4, 4, 0, 0],
| },
| },
| data: data.datay2,
| },
| ],
| };
| this.chartTimer = setInterval(function () {
| // 每次向左滑动一个,最后一个从头开始。
| if (option.dataZoom[0].endValue == that.chartData.datay.length) {
| option.dataZoom[0].startValue = 0;
| option.dataZoom[0].endValue = 5;
| } else {
| option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
| option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
| }
| myChart.setOption(option);
| }, 3000);
|
| option && myChart.setOption(option);
| window.addEventListener("resize", function () {
| myChart.resize();
| });
| } else {
| option = {};
| myChart.setOption(option, true);
| }
| },
| },
| };
| </script>
|
| <style scoped lang="scss">
| .bar-chart {
| width: 100%;
| height: calc(100% - 20px);
| padding: 20px 0 0;
| .bar-contents {
| width: 100%;
| height: calc(100% - 60px);
| border: 1px solid #00ffff;
| box-sizing: border-box;
| .bar-total {
| width: 100%;
| height: 30px;
| line-height: 30px;
| color: #dcb018;
| font-size: 14px;
| margin-top: 10px;
| .bar-item {
| width: 50%;
| text-align: center;
| float: left;
| }
| }
| .chart {
| width: 100%;
| height: calc(100% - 40px);
| }
| }
| }
| </style>
|
|