调整Y轴刻度
This commit is contained in:
@@ -111,8 +111,11 @@ const setEchart = () => {
|
||||
marker = `<span style="display:inline-block;border: 2px ${el.color} ${el.value[3]};margin-right:5px;width:40px;height:0px;background-color:#ffffff00;"></span>`
|
||||
}
|
||||
let unit = el.value[2] ? el.value[2] : ''
|
||||
str += `${marker}${el.seriesName.split('(')[0]}:${el.value[1]}${unit}
|
||||
<br>`
|
||||
// 格式化数值显示为4位小数
|
||||
const value = parseFloat(el.value[1]);
|
||||
const formattedValue = value.toFixed(4);
|
||||
|
||||
str += `${marker}${el.seriesName.split('(')[0]}:${formattedValue}${unit}<br>`
|
||||
})
|
||||
return str
|
||||
}
|
||||
@@ -157,10 +160,16 @@ const setEchart = () => {
|
||||
name: item,
|
||||
yAxisIndex: index,
|
||||
splitNumber: 5,
|
||||
minInterval: 1,
|
||||
minInterval: 0,
|
||||
splitLine: {
|
||||
show: false
|
||||
},
|
||||
axisLabel: {
|
||||
// 添加标签格式化,支持小数显示
|
||||
formatter: function(value) {
|
||||
return value.toFixed(5);
|
||||
}
|
||||
},
|
||||
...(index > 0 ? right : null)
|
||||
})
|
||||
})
|
||||
@@ -213,7 +222,7 @@ const setEchart = () => {
|
||||
let seriesList: any = []
|
||||
kk.forEach((cc: any) => {
|
||||
if (cc.statisticalData !== null) {
|
||||
yData[setList.indexOf(kk[0].unit)].push(cc.statisticalData?.toFixed(2))
|
||||
yData[setList.indexOf(kk[0].unit)].push(cc.statisticalData?.toFixed(4))
|
||||
}
|
||||
|
||||
seriesList.push([cc.time, cc.statisticalData, cc.unit, lineStyle[lineS].type])
|
||||
@@ -233,11 +242,35 @@ const setEchart = () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
// yData.forEach((item: any, index: any) => {
|
||||
// let [min, max] = yMethod(item)
|
||||
// echartsData.value.yAxis[index].min = min
|
||||
// echartsData.value.yAxis[index].max = max
|
||||
// })
|
||||
let allValues: number[] = [];
|
||||
yData.forEach(item => {
|
||||
item.forEach((val: string) => {
|
||||
allValues.push(val);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// 计算全局最大最小值
|
||||
let globalMin = Math.min(...allValues) - 0.0001;
|
||||
let globalMax = Math.max(...allValues) +0.0001
|
||||
|
||||
// 确保最小值不小于0
|
||||
globalMin = Math.max(0, globalMin);
|
||||
|
||||
// 特殊情况:如果所有值都是0
|
||||
if (globalMin === 0 && globalMax === 0) {
|
||||
globalMax = 1;
|
||||
}
|
||||
// 为所有Y轴应用相同的范围
|
||||
yData.forEach((item: any, index: any) => {
|
||||
let [min, max] = yMethod(item)
|
||||
echartsData.value.yAxis[index].min = min
|
||||
echartsData.value.yAxis[index].max = max
|
||||
})
|
||||
echartsData.value.yAxis[index].min = globalMin ;
|
||||
echartsData.value.yAxis[index].max = globalMax;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user