From 230021a7b69673476f3065c376c0b6f6ec30b6d6 Mon Sep 17 00:00:00 2001 From: tangweijie <877588133@qq.com> Date: Fri, 23 Jan 2026 11:38:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(dashboard):=20=E4=BC=98=E5=8C=96=E9=A3=8E?= =?UTF-8?q?=E9=99=A9=E8=B6=8B=E5=8A=BF=E5=9B=BEY=E8=BD=B4=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=BC=A9=E6=94=BE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据数据范围自动计算合适的Y轴最大值和刻度间隔: - 小于等于10:向上取整到整数 - 10-50:向上取整到10的倍数 - 50-100:向上取整到10的倍数 - 100-500:向上取整到50的倍数 - 500-1000:向上取整到100的倍数 - 大于1000:向上取整到500的倍数 自动计算刻度间隔,确保显示6-8个刻度,提升图表可读性 --- src/views/DashEntry/DashEntry.vue | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/views/DashEntry/DashEntry.vue b/src/views/DashEntry/DashEntry.vue index f6922b06..3a187081 100644 --- a/src/views/DashEntry/DashEntry.vue +++ b/src/views/DashEntry/DashEntry.vue @@ -281,7 +281,32 @@ const riskTrendOptions = computed(() => { // 计算最大值用于设置Y轴范围 const allValues = [...highRiskData, ...warningData, ...normalData] const maxValue = Math.max(...allValues, 10) - const yAxisMax = Math.ceil(maxValue / 50) * 50 + 50 + + // 动态计算Y轴最大值,根据数据范围自动向上取整到合适的量级 + let yAxisMax: number + if (maxValue === 0) { + yAxisMax = 10 + } else if (maxValue <= 10) { + yAxisMax = Math.ceil(maxValue) + } else if (maxValue <= 50) { + // 对于10-50的数据,向上取整到10的倍数 + yAxisMax = Math.ceil(maxValue / 10) * 10 + } else if (maxValue <= 100) { + // 对于50-100的数据,向上取整到10的倍数 + yAxisMax = Math.ceil(maxValue / 10) * 10 + } else if (maxValue <= 500) { + // 对于100-500的数据,向上取整到50的倍数 + yAxisMax = Math.ceil(maxValue / 50) * 50 + } else if (maxValue <= 1000) { + // 对于500-1000的数据,向上取整到100的倍数 + yAxisMax = Math.ceil(maxValue / 100) * 100 + } else { + // 对于大于1000的数据,向上取整到500的倍数 + yAxisMax = Math.ceil(maxValue / 500) * 500 + } + + // 计算合适的刻度间隔,确保显示6-8个刻度 + const interval = Math.max(Math.ceil(yAxisMax / 6), 1) return { tooltip: { @@ -306,7 +331,7 @@ const riskTrendOptions = computed(() => { type: 'value', min: 0, max: yAxisMax, - interval: Math.ceil(yAxisMax / 6) + interval: interval }, series: [ {