|
|
@@ -119,23 +119,19 @@ const loadStations = async () => {
|
|
|
};
|
|
|
|
|
|
const buildOption = (forecastStats, localStats) => {
|
|
|
- const toMap = (stats, key) => {
|
|
|
- const map = new Map();
|
|
|
- (stats || []).forEach((item) => map.set(item.time, toNumber(item[key], 0)));
|
|
|
- return map;
|
|
|
- };
|
|
|
- const forecastMap = toMap(forecastStats, 'rhsfc');
|
|
|
- const localMap = toMap(localStats, 'rhsfc');
|
|
|
- const times = [...new Set([...forecastMap.keys(), ...localMap.keys()])].sort();
|
|
|
+ // 预测/本地采样时间点不同,用连续时间轴各自按自身采样点绘制,避免线条因对方缺数而中断
|
|
|
+ // 按时间戳排序,保证数组顺序与时间一致,避免后端返回无序导致线条自我交叉
|
|
|
+ const toPairs = (stats, key) => (stats || [])
|
|
|
+ .map((item) => [dayjs(item.time).valueOf(), toNumber(item[key], 0)])
|
|
|
+ .sort((a, b) => a[0] - b[0]);
|
|
|
return {
|
|
|
tooltip: {trigger: 'axis'},
|
|
|
legend: {top: 0, left: 'center', data: ['预测', '本地']},
|
|
|
grid: {left: 60, right: 24, top: 46, bottom: 60},
|
|
|
xAxis: {
|
|
|
- type: 'category',
|
|
|
- boundaryGap: false,
|
|
|
- data: times,
|
|
|
- axisLabel: {color: '#5a6a85'}
|
|
|
+ type: 'time',
|
|
|
+ axisLabel: {color: '#5a6a85'},
|
|
|
+ axisPointer: {snap: true}
|
|
|
},
|
|
|
yAxis: {
|
|
|
type: 'value',
|
|
|
@@ -148,8 +144,8 @@ const buildOption = (forecastStats, localStats) => {
|
|
|
{type: 'slider', height: 18, bottom: 12, start: 0, end: 100}
|
|
|
],
|
|
|
series: [
|
|
|
- {name: '预测', type: 'line', smooth: true, showSymbol: false, data: times.map((t) => (forecastMap.has(t) ? forecastMap.get(t) : null))},
|
|
|
- {name: '本地', type: 'line', smooth: true, showSymbol: false, data: times.map((t) => (localMap.has(t) ? localMap.get(t) : null))}
|
|
|
+ {name: '预测', type: 'line', smooth: true, showSymbol: false, data: toPairs(forecastStats, 'rhsfc')},
|
|
|
+ {name: '本地', type: 'line', smooth: true, showSymbol: false, data: toPairs(localStats, 'rhsfc')}
|
|
|
]
|
|
|
};
|
|
|
};
|