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',