feat(dashboard): 优化风险趋势图Y轴动态缩放逻辑

根据数据范围自动计算合适的Y轴最大值和刻度间隔:
- 小于等于10:向上取整到整数
- 10-50:向上取整到10的倍数
- 50-100:向上取整到10的倍数
- 100-500:向上取整到50的倍数
- 500-1000:向上取整到100的倍数
- 大于1000:向上取整到500的倍数

自动计算刻度间隔,确保显示6-8个刻度,提升图表可读性
This commit is contained in:
tangweijie 2026-01-23 11:38:08 +08:00
parent 33cc05cb00
commit 230021a7b6

View File

@ -281,7 +281,32 @@ const riskTrendOptions = computed<EChartsOption>(() => {
// 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-5010
yAxisMax = Math.ceil(maxValue / 10) * 10
} else if (maxValue <= 100) {
// 50-10010
yAxisMax = Math.ceil(maxValue / 10) * 10
} else if (maxValue <= 500) {
// 100-50050
yAxisMax = Math.ceil(maxValue / 50) * 50
} else if (maxValue <= 1000) {
// 500-1000100
yAxisMax = Math.ceil(maxValue / 100) * 100
} else {
// 1000500
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<EChartsOption>(() => {
type: 'value',
min: 0,
max: yAxisMax,
interval: Math.ceil(yAxisMax / 6)
interval: interval
},
series: [
{