From 77c7c18f7611057261e4067ce38854fe8004a418 Mon Sep 17 00:00:00 2001 From: haoliang <821644@qq.com> Date: Tue, 19 May 2026 17:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=BA=8A=E4=BA=A7=E9=87=8F=E6=9F=B1?= =?UTF-8?q?=E7=8A=B6=E5=9B=BE=E6=8C=89=E6=9C=BA=E5=BA=8A=E8=81=9A=E5=90=88?= =?UTF-8?q?+TOP=20N=E4=B8=8B=E6=8B=89=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/production/MachineProduction.vue | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/production/MachineProduction.vue b/frontend/src/views/production/MachineProduction.vue index 7d087eb..0f92cbc 100644 --- a/frontend/src/views/production/MachineProduction.vue +++ b/frontend/src/views/production/MachineProduction.vue @@ -115,7 +115,18 @@
@@ -201,14 +212,20 @@ const options = reactive({ const barChartRef = ref() let barChart: ECharts | null = null -/** 初始化柱状图 */ +const barChartTopN = ref(10) + +/** 初始化柱状图(按机床聚合,取TOP N) */ function initBarChart() { if (!barChartRef.value || !tableData.value.length) return if (barChart) barChart.dispose() barChart = echarts.init(barChartRef.value) - const names = tableData.value.map((i) => i.machineName) - const quantities = tableData.value.map((i) => i.totalQuantity) - const total = tableData.value.reduce((sum, i) => sum + i.totalQuantity, 0) + // 按机床名聚合产量 + const machineMap = new Map() + tableData.value.forEach(i => machineMap.set(i.machineName, (machineMap.get(i.machineName)||0) + i.totalQuantity)) + const sorted = [...machineMap.entries()].sort((a,b) => b[1] - a[1]).slice(0, barChartTopN.value) + const names = sorted.map(e => e[0]) + const quantities = sorted.map(e => e[1]) + const total = quantities.reduce((s, v) => s + v, 0) barChart.setOption({ tooltip: { trigger: 'axis',