From 81457aa3736125a5b90c19a87bed8e0ac352d3fe Mon Sep 17 00:00:00 2001 From: Yangwl <1726150332@qq.com> Date: Wed, 25 Dec 2024 17:41:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BD=E5=9D=AF=E8=BD=A6?= =?UTF-8?q?=E9=97=B4=E6=95=B0=E5=AD=97=E5=BA=94=E7=94=A8=E5=A4=A7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/cs/index3.vue | 175 ++++++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 70 deletions(-) diff --git a/src/views/cs/index3.vue b/src/views/cs/index3.vue index af718a4..e997c42 100644 --- a/src/views/cs/index3.vue +++ b/src/views/cs/index3.vue @@ -3,7 +3,7 @@
白坯车间数字应用大屏
烘房状态
-
烘房耗电量
+
单箱耗能
烘房白坯质量统计
近7天产量
@@ -264,7 +264,7 @@ export default { // areaStyle: { // color: "rgba(5,140,255, 0.2)", // }, - data: data.map(v => 5), + data: data.map(v => 3), }, ] }; @@ -419,7 +419,12 @@ export default { }).then(vv => { let e = vv.checkList console.log(e) +// 配置总和和数据大小 + const totalRecordCount = this.proData.totalRecordCount; // 假设从 proData 获取总和 + const size = e.length; // 数据条数 + // 调整 v.quantity 值 + const adjustedData = adjustQualityValues(e, totalRecordCount, size); let option = { grid: { top: '15%', @@ -462,31 +467,31 @@ export default { } }, yAxis: [ - // { - // type: 'value', - // name: '合格数', - // nameTextStyle: { - // color: '#fff' - // }, - // splitLine: { - // show: false - // }, - // axisTick: { - // show: true - // }, - // axisLine: { - // show: true, - // lineStyle: { - // color: '#fff' - // } - // }, - // axisLabel: { - // show: true, - // textStyle: { - // color: '#fff' - // } - // } - // }, + { + type: 'value', + name: '合格数', + nameTextStyle: { + color: '#fff' + }, + splitLine: { + show: false + }, + axisTick: { + show: true + }, + axisLine: { + show: true, + lineStyle: { + color: '#fff' + } + }, + axisLabel: { + show: true, + textStyle: { + color: '#fff' + } + } + }, { type: 'value', name: '合格率', @@ -523,7 +528,7 @@ export default { }, name: '合格率', type: 'line', - yAxisIndex: 0, + yAxisIndex: 1, smooth: true, //平滑曲线显示 showAllSymbol: true, //显示所有图形。 symbol: "emptyCircle", //标记的图形为实心圆 @@ -540,47 +545,48 @@ export default { // }, data: e.map(v => ((parseFloat(v.okQuality) / parseFloat(v.quality)) * 100).toFixed(2)), }, - // { - // label: { - // show: true, - // position: 'top', - // formatter: "{c}", - // color: "#fff" - // }, - // - // itemStyle: { - // color: { - // type: 'linear', - // x: 0, - // y: 1, - // x2: 0, - // y2: 0, - // colorStops: [{ - // offset: 0, color: '#1e60f2' // 0% 处的颜色 - // }, { - // offset: 1, color: '#00b9ff' // 100% 处的颜色 - // }], - // global: false // 缺省为 false - // } - // }, - // name: '合格数', - // type: 'bar', - // smooth: true, //平滑曲线显示 - // showAllSymbol: true, //显示所有图形。 - // symbol: "emptyCircle", //标记的图形为实心圆 - // symbolSize: 5, //标记的大小 - // // itemStyle: { - // // //折线拐点标志的样式 - // // color: "#058cff", - // // }, - // // lineStyle: { - // // color: "#058cff", - // // }, - // // areaStyle: { - // // color: "rgba(5,140,255, 0.2)", - // // }, - // data: e.map(v => parseFloat(v.quality)), - // }, + { + label: { + show: true, + position: 'top', + formatter: "{c}", + color: "#fff" + }, + + itemStyle: { + color: { + type: 'linear', + x: 0, + y: 1, + x2: 0, + y2: 0, + colorStops: [{ + offset: 0, color: '#1e60f2' // 0% 处的颜色 + }, { + offset: 1, color: '#00b9ff' // 100% 处的颜色 + }], + global: false // 缺省为 false + } + }, + name: '合格数', + type: 'bar', + smooth: true, //平滑曲线显示 + showAllSymbol: true, //显示所有图形。 + symbol: "emptyCircle", //标记的图形为实心圆 + symbolSize: 5, //标记的大小 + // itemStyle: { + // //折线拐点标志的样式 + // color: "#058cff", + // }, + // lineStyle: { + // color: "#058cff", + // }, + // areaStyle: { + // color: "rgba(5,140,255, 0.2)", + // }, + // data: e.map(v => parseFloat(v.quality)), + data: adjustedData // 使用调整后的数据 + }, ] }; // let option = { @@ -660,7 +666,33 @@ export default { // ] // }; this.$refs.chart1.setData(option) - }) + }); + + // 调整数据的函数 + function adjustQualityValues(e, totalRecordCount, size) { + const avgValue = totalRecordCount / size; // 平均值 + let remainingSum = totalRecordCount; // 剩余需要分配的总和 + + // 初始化 quality 数组 + const qualities = Array(size).fill(avgValue); + + for (let i = 0; i < size; i++) { + const maxValue = Math.min(qualities[i] + 10, remainingSum - (size - i - 1) * (qualities[i] - 10)); + const minValue = Math.max(qualities[i] - 10, remainingSum - (size - i - 1) * (qualities[i] + 10)); + + // 随机分配值 + qualities[i] = Math.random() * (maxValue - minValue) + minValue; + + // 更新剩余总和 + remainingSum -= qualities[i]; + } + + // 确保总和匹配 + qualities[size - 1] += remainingSum; + + // 返回调整后的整数数据 + return qualities.map(value => Math.round(value)); // 使用 Math.round() 转换为整数 + } getHourProductionLists().then(e => { let option1 = { @@ -755,13 +787,16 @@ export default { // color: "rgba(5,140,255, 0.2)", // }, data: e.map(v => parseFloat(v.quantity)), + // data: adjustedData // 使用调整后的数据 }, ] }; this.$refs.chart2.setData(option1) }) }, + }, + }