|
|
|
|
@ -115,7 +115,18 @@
|
|
|
|
|
<el-col :span="24">
|
|
|
|
|
<el-card shadow="hover">
|
|
|
|
|
<template #header>
|
|
|
|
|
<span class="card-title">机床产量柱状图</span>
|
|
|
|
|
<div style="display:flex;justify-content:space-between;align-items:center">
|
|
|
|
|
<span class="card-title">机床产量柱状图</span>
|
|
|
|
|
<div style="display:flex;align-items:center;gap:6px">
|
|
|
|
|
<span style="font-size:13px;color:#909399">TOP</span>
|
|
|
|
|
<el-select v-model="barChartTopN" size="small" style="width:80px" @change="initBarChart" filterable allow-create>
|
|
|
|
|
<el-option :value="10" label="10"/>
|
|
|
|
|
<el-option :value="20" label="20"/>
|
|
|
|
|
<el-option :value="50" label="50"/>
|
|
|
|
|
<el-option :value="100" label="100"/>
|
|
|
|
|
</el-select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<div ref="barChartRef" style="height: 350px"></div>
|
|
|
|
|
</el-card>
|
|
|
|
|
@ -201,14 +212,20 @@ const options = reactive({
|
|
|
|
|
const barChartRef = ref<HTMLElement>()
|
|
|
|
|
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<string, number>()
|
|
|
|
|
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',
|
|
|
|
|
|