diff --git a/src/views/statistics/ppass_num.vue b/src/views/statistics/ppass_num.vue index 6771b5ed..d1b37871 100644 --- a/src/views/statistics/ppass_num.vue +++ b/src/views/statistics/ppass_num.vue @@ -40,7 +40,9 @@ - +
+ +
@@ -128,9 +130,21 @@ export default { type: "category", data: [], }, - yAxis: { - type: "value", - }, + yAxis: [ + { + type: "value", + name: "数量", + }, + { + type: "value", + name: "合格率", + min: 0, + max: 100, + axisLabel: { + formatter: "{value}%", + }, + }, + ], series: [], }, nameFilters: [], @@ -189,43 +203,73 @@ export default { obj.query.order_bys_date = ", 月"; } let xAxisData = [],nameData=[],seriesData=[]; + let colorPalette = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']; that.$API.bi.dataset.exec.req("lineWeek", obj).then((res) => { let data = res.data2.ds0; that.tableData = data; data.forEach((item) => { - if (xAxisData.indexOf(item.工段) > -1) { - } else { + if (xAxisData.indexOf(item.工段) === -1) { xAxisData.push(item.工段); - let obj = {}; - obj.text = item.工段; - obj.value = item.工段; - that.mgroupFilters.push(obj); + that.mgroupFilters.push({ text: item.工段, value: item.工段 }); } - if (nameData.indexOf(item.物料名) > -1) { - } else { - let obj0 = {}; - obj0.text = item.物料名; - obj0.value = item.物料名; - that.nameFilters.push(obj0); + if (nameData.indexOf(item.物料名) === -1) { nameData.push(item.物料名); - let obj = { - name:'', - type: "bar", - label:{ - show: true, - position: "top", - formatter: "{c}", - color: "rgb(64,158,255)", - }, - barWidth: "15px", - data:[0, 0, 0, 0, 0, 0, 0, 0], - }; - obj.name=item.物料名, - seriesData.push(obj); + that.nameFilters.push({ text: item.物料名, value: item.物料名 }); } - let index = xAxisData.indexOf(item.工段); - let indexY = nameData.indexOf(item.物料名); - seriesData[indexY].data[index] += item.合格数; + }); + nameData.forEach((materialName, idx) => { + let color = colorPalette[idx % colorPalette.length]; + let barData = xAxisData.map((mgroup) => { + let qualified = 0; + data.forEach((item) => { + if (item.工段 === mgroup && item.物料名 === materialName) { + qualified += Number(item.合格数) || 0; + } + }); + return qualified; + }); + let passRateData = xAxisData.map((mgroup) => { + let qualified = 0; + let produced = 0; + data.forEach((item) => { + if (item.工段 === mgroup && item.物料名 === materialName) { + qualified += Number(item.合格数) || 0; + produced += Number(item.生产数) || 0; + } + }); + return produced > 0 + ? Number(((qualified / produced) * 100).toFixed(2)) + : null; + }); + seriesData.push({ + name: materialName, + type: "bar", + yAxisIndex: 0, + itemStyle: { color }, + label: { + show: true, + position: "top", + formatter: "{c}", + color: color, + }, + barWidth: "15px", + data: barData, + }); + seriesData.push({ + name: materialName + " 合格率", + type: "line", + yAxisIndex: 1, + smooth: true, + data: passRateData, + label: { + show: true, + position: "top", + formatter: "{c}%", + color: color, + }, + lineStyle: { color }, + itemStyle: { color }, + }); }); that.xAxisData = xAxisData; that.option.xAxis.data = that.xAxisData;