From 7e24cc52c9c380194fa7a480cb11dead2c5e6bb7 Mon Sep 17 00:00:00 2001 From: yarnom Date: Fri, 29 Aug 2025 23:14:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/weather-chart.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/static/js/weather-chart.js b/static/js/weather-chart.js index 0521079..0bafcd8 100644 --- a/static/js/weather-chart.js +++ b/static/js/weather-chart.js @@ -87,7 +87,8 @@ const WeatherChart = { backgroundColor: 'rgba(255, 99, 132, 0.1)', yAxisID: 'y-temperature', tension: 0.4, - spanGaps: false + spanGaps: false, + legendGroup: 'history' }, { label: '湿度 (%) - 实测', @@ -97,7 +98,8 @@ const WeatherChart = { yAxisID: 'y-humidity', tension: 0.4, hidden: true, - spanGaps: false + spanGaps: false, + legendGroup: 'history' }, { label: '雨量 (mm) - 实测', @@ -105,7 +107,8 @@ const WeatherChart = { type: 'bar', backgroundColor: 'rgba(54, 162, 235, 0.6)', borderColor: 'rgb(54, 162, 235)', - yAxisID: 'y-rainfall' + yAxisID: 'y-rainfall', + legendGroup: 'history' }, { label: '累计雨量 (mm) - 实测', @@ -116,16 +119,17 @@ const WeatherChart = { tension: 0.2, spanGaps: false, pointRadius: 0, - hidden: true + hidden: true, + legendGroup: 'history' } ]; if (forecastData.length > 0) { // 雨量 仅显示 -1h/-2h/-3h datasets.push( - { label: '雨量 (mm) - 预报 (+1h)', data: forecastRainfallsH1, type: 'bar', backgroundColor: 'rgba(255, 99, 71, 0.55)', borderColor: 'rgb(255, 99, 71)', yAxisID: 'y-rainfall' }, - { label: '雨量 (mm) - 预报 (+2h)', data: forecastRainfallsH2, type: 'bar', backgroundColor: 'rgba(255, 205, 86, 0.55)', borderColor: 'rgb(255, 205, 86)', yAxisID: 'y-rainfall' }, - { label: '雨量 (mm) - 预报 (+3h)', data: forecastRainfallsH3, type: 'bar', backgroundColor: 'rgba(76, 175, 80, 0.55)', borderColor: 'rgb(76, 175, 80)', yAxisID: 'y-rainfall' } + { label: '雨量 (mm) - 预报 (+1h)', data: forecastRainfallsH1, type: 'bar', backgroundColor: 'rgba(255, 99, 71, 0.55)', borderColor: 'rgb(255, 99, 71)', yAxisID: 'y-rainfall', legendGroup: 'forecast' }, + { label: '雨量 (mm) - 预报 (+2h)', data: forecastRainfallsH2, type: 'bar', backgroundColor: 'rgba(255, 205, 86, 0.55)', borderColor: 'rgb(255, 205, 86)', yAxisID: 'y-rainfall', legendGroup: 'forecast' }, + { label: '雨量 (mm) - 预报 (+3h)', data: forecastRainfallsH3, type: 'bar', backgroundColor: 'rgba(76, 175, 80, 0.55)', borderColor: 'rgb(76, 175, 80)', yAxisID: 'y-rainfall', legendGroup: 'forecast' } ); // 温度 取最接近的预报(0h>1h>2h>3h) @@ -137,7 +141,8 @@ const WeatherChart = { borderDash: [5, 5], yAxisID: 'y-temperature', tension: 0.4, - spanGaps: false + spanGaps: false, + legendGroup: 'forecast' }); } @@ -153,6 +158,20 @@ const WeatherChart = { responsive: true, maintainAspectRatio: false, interaction: { mode: 'index', intersect: false }, + plugins: { + legend: { + position: 'top', + align: 'center', + labels: { + boxWidth: 30, + padding: 15, + font: { + size: 11 + } + }, + maxHeight: 80 + } + }, scales: { 'y-temperature': { type: 'linear', display: true, position: 'left', title: { display: true, text: '温度 (°C)' } }, 'y-humidity': { type: 'linear', display: true, position: 'right', title: { display: true, text: '湿度 (%)' }, grid: { drawOnChartArea: false }, min: 0, max: 100 },