浏览代码

图表x轴对应准确性修正

Karsa 1 年之前
父节点
当前提交
3315544770
共有 1 个文件被更改,包括 17 次插入28 次删除
  1. 17 28
      src/views/hzyb/chart/Detail.vue

+ 17 - 28
src/views/hzyb/chart/Detail.vue

@@ -8,7 +8,7 @@ import {ref,onMounted, reactive, watch,computed,nextTick} from 'vue'
 import {useRoute, useRouter,onBeforeRouteUpdate} from 'vue-router'
 import moment from 'moment'
 import _ from 'lodash';
-import Highcharts from 'highcharts/highstock';
+import Highcharts from 'highcharts';
 import {
     apiChartInfo,
     apiChartList,
@@ -1197,24 +1197,17 @@ const setSplineOpt=(data)=>{
     let maxTime=Math.max.apply(null,minAndMaxTimeTemArr)
 
 
-    const bool_time = xTimeDiffer(minTime,maxTime)
-    if(bool_time){
-        xAxis={
-            ...basicXAxis,
-            labels: {
-              formatter: (ctx)=> {
-                return Highcharts.dateFormat('%m/%d', ctx.value)
-              }
-            }
-        }
-    }
-    // console.log(((maxTime-minTime)/6)/(24*3600*1000),':天');
-    // let maxYear=new Date(maxTime).getFullYear()
-    // let minYear=new Date(minTime).getFullYear()
-
+    const isLessThanOneYear = xTimeDiffer(minTime,maxTime)
     xAxis={
         ...basicXAxis,
         tickInterval:((maxTime-minTime)/6)/(24*3600*1000)>30?(maxTime-minTime)/6:24*3600*1000*30,
+        labels: {
+            formatter:  (ctx)=> {
+                return isLessThanOneYear
+                ? Highcharts.dateFormat('%m/%d', ctx.value)
+                : Highcharts.dateFormat('%y/%m', ctx.value);
+            }
+        },
     }
     
     chartData.value.xAxis=[xAxis]
@@ -1411,21 +1404,17 @@ const setStackOrCombinChart = data => {
     let maxTime=Math.max.apply(null,minAndMaxTimeTemArr)
 
 
-    const bool_time = xTimeDiffer(minTime,maxTime)
-    if(bool_time){
-        xAxis={
-            ...basicXAxis,
-            labels: {
-              formatter: (ctx)=> {
-                return Highcharts.dateFormat('%m/%d', ctx.value)
-              }
-            }
-        }
-    }
-
+    const isLessThanOneYear = xTimeDiffer(minTime,maxTime)
     xAxis={
         ...basicXAxis,
         tickInterval:((maxTime-minTime)/6)/(24*3600*1000)>30?(maxTime-minTime)/6:24*3600*1000*30,
+        labels: {
+            formatter: (ctx)=> {
+                return isLessThanOneYear
+                ? Highcharts.dateFormat('%m/%d', ctx.value)
+                : Highcharts.dateFormat('%y/%m', ctx.value);
+            }
+        },
     }
     
     chartData.value.xAxis=[xAxis]