Commit 70b02751 authored by xinzhedeai's avatar xinzhedeai

左侧降雨量没有默认值

parent cae519e6
...@@ -38,17 +38,49 @@ const showNoData = ref(false); ...@@ -38,17 +38,49 @@ const showNoData = ref(false);
// const DEFAULT_Y_AXIS_MAX = 250; // Y轴最大值 // const DEFAULT_Y_AXIS_MAX = 250; // Y轴最大值
// const DEFAULT_Y_AXIS_MIN = 0; // Y轴最小值 // const DEFAULT_Y_AXIS_MIN = 0; // Y轴最小值
// 新增:计算y轴最大值(包含数据和警戒线,并预留空间)
const getYAxisMax = () => {
// 处理空数据情况
if (yAxisData.value.length === 0 && warningLines.value.length === 0) {
return 10; // 无数据时默认最大值
}
// 获取实际数据的最大值
const dataMax = yAxisData.value.length > 0
? Math.max(...yAxisData.value)
: 0;
// 获取警戒线的最大值
const warningMax = warningLines.value.length > 0
? Math.max(...warningLines.value.map(line => line.value))
: 0;
// 取两者中的较大值作为基准
const baseMax = Math.max(dataMax, warningMax);
// 增加20%的冗余空间(可根据需求调整比例)
const redundant = baseMax * 0.2;
// 确保最小值至少为10,避免数值过小导致图表显示异常
return Math.max(baseMax + redundant, 0.5);
};
// 模拟接口请求函数 // 模拟接口请求函数
const fetchRainCurve = async () => { const fetchRainCurve = async () => {
const response = await getRainCurve(); const response = await getRainCurve();
console.log('降雨量',response.data) console.log('降雨量',response.data)
const result = response.data const result = response.data
if (result.code == 200) { if (result.code == 200) {
// result.data.ydata= []
// 处理空数据情况 // 处理空数据情况
if (!result.data || !result.data.ydata || result.data.ydata.length === 0) { if (!result.data || !result.data.ydata || result.data.ydata.length === 0) {
// 显示"暂无数据"提示 // 显示"暂无数据"提示
showNoData.value = true; showNoData.value = true;
yAxisData.value = [0]
xAxisData.value = [0]
} else { } else {
// 隐藏"暂无数据"提示 // 隐藏"暂无数据"提示
showNoData.value = false; showNoData.value = false;
...@@ -93,10 +125,9 @@ const updateChartData = () => { ...@@ -93,10 +125,9 @@ const updateChartData = () => {
xAxis: { xAxis: {
data: xAxisData.value data: xAxisData.value
}, },
// yAxis: { yAxis: {
// min: DEFAULT_Y_AXIS_MIN, max: getYAxisMax() // 应用动态计算的最大值
// max: DEFAULT_Y_AXIS_MAX },
// },
series: [{ series: [{
data: yAxisData.value, data: yAxisData.value,
markLine: { markLine: {
...@@ -146,6 +177,7 @@ const initChart = () => { ...@@ -146,6 +177,7 @@ const initChart = () => {
padding: [0, 38, 0, 0], padding: [0, 38, 0, 0],
}, },
type: "value", type: "value",
max: getYAxisMax(),
// max: 300, // max: 300,
// min: DEFAULT_Y_AXIS_MIN, // 设置Y轴最小值 // min: DEFAULT_Y_AXIS_MIN, // 设置Y轴最小值
// max: DEFAULT_Y_AXIS_MAX, // 设置Y轴最大值 // max: DEFAULT_Y_AXIS_MAX, // 设置Y轴最大值
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment