Browse Source

fix:修改巡园平台气象数据

wangsisi 1 month ago
parent
commit
80e2960721
1 changed files with 34 additions and 12 deletions
  1. 34 12
      src/components/charts/options/oneLineOption.js

+ 34 - 12
src/components/charts/options/oneLineOption.js

@@ -1,5 +1,27 @@
 import * as echarts from "echarts";
 
+function formatDateToMMDD(date) {
+    const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始,需要加1,并确保是两位数
+    const day = String(date.getDate()).padStart(2, "0"); // 确保日期是两位数
+    return `${month}/${day}`;
+}
+
+function getCurrentDateAndNextSixDaysMMDD() {
+    const currentDate = new Date();
+    const dates = [];
+
+    for (let i = 0; i <= 6; i++) {
+        const newDate = new Date(currentDate);
+        newDate.setDate(currentDate.getDate() + i);
+        const formattedDate = formatDateToMMDD(newDate);
+        dates.push(formattedDate);
+    }
+
+    return dates;
+}
+
+const list = getCurrentDateAndNextSixDaysMMDD();
+const arr = [16, 17, 14, 20, 28, 21, 22]
 
 export const oneLine = {
     tooltip: {
@@ -35,7 +57,7 @@ export const oneLine = {
                 color: "rgba(185, 185, 185, 0.12)",
             }
         },
-        data: ['2/12', '2/13', '2/14', '2/15', '2/16', '2/17', '2/18']
+        data: list
     },
     yAxis: [{
         type: 'value',
@@ -67,7 +89,7 @@ export const oneLine = {
     series: [
         {
             name: "温度",
-            data: [19, 18, 11, 20, 23, 18, 22],
+            data: arr,
             type: 'line',
             smooth: true,
             symbol: "none",
@@ -89,11 +111,11 @@ export const oneLine = {
                     {
                         name: "text",
                         value: "最高",
-                        xAxis: '2/16',
-                        yAxis: 23,
+                        xAxis: list[4],
+                        yAxis: arr[4],
                         symbolOffset: [0, "-50%"],
                         label: {
-                            offset: [0, 22],
+                            offset: [0, 15],
                             color: "#fff",
                             height: 20,
                             borderRadius: 10,
@@ -101,8 +123,8 @@ export const oneLine = {
                     },
                     {
                         name: "mark",
-                        xAxis: '2/16',
-                        yAxis: 23,
+                        xAxis: list[4],
+                        yAxis: arr[4],
                         value: "",
                         label: {
                             backgroundColor: "#fff",
@@ -116,11 +138,11 @@ export const oneLine = {
                     {
                         name: "text",
                         value: "最低",
-                        xAxis: '2/14',
-                        yAxis: 11,
+                        xAxis: list[2],
+                        yAxis: arr[2],
                         symbolOffset: [0, "-50%"],
                         label: {
-                            offset: [0, 22],
+                            offset: [0, 15],
                             color: "#fff",
                             height: 20,
                             borderRadius: 10,
@@ -128,8 +150,8 @@ export const oneLine = {
                     },
                     {
                         name: "mark",
-                        xAxis: '2/14',
-                        yAxis: 11,
+                        xAxis: list[2],
+                        yAxis: arr[2],
                         value: "",
                         label: {
                             backgroundColor: "#fff",