Browse Source

BASE优化

九山 3 years ago
parent
commit
0e715c27b7
3 changed files with 20 additions and 71 deletions
  1. 8 12
      src/assets/js/index/index.js
  2. 2 46
      src/tools/base.js
  3. 10 13
      src/tools/echartsTool.js

+ 8 - 12
src/assets/js/index/index.js

@@ -56,15 +56,14 @@ export default {
             lineStyle: { // 属性lineStyle控制线条样式
               width: 12,
               color: [ // 设置分段颜色
-                [0.5, "#4dabf7"],
-                [0.65, "#69db7c"],
+                [0.5, "#69db7c"],
                 [0.8, "#ffa94d"],
                 [1, "#ff6b6b"]
               ]
             }
           },
           axisLabel: {
-            distance: -15, // 标签与刻度线的距离。
+            distance: -5, // 标签与刻度线的距离。
             formatter: function (value) {
               return Math.ceil(value);
             }
@@ -102,15 +101,14 @@ export default {
             lineStyle: { // 属性lineStyle控制线条样式
               width: 12,
               color: [ // 设置分段颜色
-                [0.5, "#4dabf7"],
-                [0.65, "#69db7c"],
+                [0.5, "#69db7c"],
                 [0.8, "#ffa94d"],
                 [1, "#ff6b6b"]
               ]
             }
           },
           axisLabel: {
-            distance: -15, // 标签与刻度线的距离。
+            distance: -5, // 标签与刻度线的距离。
             formatter: function (value) {
               return Math.ceil(value);
             }
@@ -148,15 +146,14 @@ export default {
             lineStyle: {       // 属性lineStyle控制线条样式
               width: 12,
               color: [ // 设置分段颜色
-                [0.5, "#4dabf7"],
-                [0.65, "#69db7c"],
+                [0.5, "#69db7c"],
                 [0.8, "#ffa94d"],
                 [1, "#ff6b6b"]
               ]
             }
           },
           axisLabel: {
-            distance: -15, // 标签与刻度线的距离。
+            distance: -5, // 标签与刻度线的距离。
             formatter: function (value) {
               return Math.ceil(value);
             }
@@ -194,15 +191,14 @@ export default {
             lineStyle: {       // 属性lineStyle控制线条样式
               width: 12,
               color: [ // 设置分段颜色
-                [0.5, "#4dabf7"],
-                [0.65, "#69db7c"],
+                [0.5, "#69db7c"],
                 [0.8, "#ffa94d"],
                 [1, "#ff6b6b"]
               ]
             }
           },
           axisLabel: {
-            distance: -15, // 标签与刻度线的距离。
+            distance: -5, // 标签与刻度线的距离。
             formatter: function (value) {
               return Math.ceil(value);
             }

+ 2 - 46
src/tools/base.js

@@ -149,58 +149,14 @@ export function getNewNum(nStr) {
 
 /*
  *  对一个数字上取舍,如1234,取舍结果是2000。
- *  适配万亿级别的数字
+ *  适配万亿级别的数字,无上限
  *  num: 数字
  * */
 export function numberCeil(num) {
   num = Math.ceil(num);
   let indexNum = (num+"").length;
   let result = 0;
-  let w = 1;
-  
-  switch(indexNum) {
-    case 1:
-      w = 1;
-      break;
-    case 2:
-      w = 10;
-      break;
-    case 3:
-      w = 100;
-      break;
-    case 4:
-      w = 1000;
-      break;
-    case 5:
-      w = 10000;
-      break;
-    case 6:
-      w = 100000;
-      break;
-    case 7:
-      w = 1000000;
-      break;
-    case 8:
-      w = 10000000;
-      break;
-    case 9:
-      w = 100000000;
-      break;
-    case 10:
-      w = 1000000000;
-      break;
-    case 11:
-      w = 10000000000;
-      break;
-    case 12:
-      w = 100000000000;
-      break;
-    case 13:
-      w = 1000000000000;
-      break;
-    default:
-      w = 1;
-  } 
+  let w = Math.pow(10,(indexNum - 1));
   result = Math.ceil(num/w)*w;
   return result;
 }

+ 10 - 13
src/tools/echartsTool.js

@@ -235,7 +235,7 @@ export function getLine(id, legendData, x, data) {
     Message.error("没有找到报表数据,请检查!");
     return;
   }
-  let maxMin = getMax(data); // 计算最大值
+  let max = getMax(data); // 计算最大值
   var myChart = EC.init(document.getElementById(id));
   let option = {
     tooltip: {
@@ -280,10 +280,10 @@ export function getLine(id, legendData, x, data) {
       axisTick: {
         show: false
       },
-      min:maxMin[0][1],
-      max:maxMin[0][0],
-      splitNumber:5,
-      interval: (maxMin[0][0]-maxMin[0][1])/5
+      min: 0,
+      max: max[0],
+      splitNumber: 5,
+      interval: max[0]/5
     },
     {
       type: 'value',
@@ -294,10 +294,10 @@ export function getLine(id, legendData, x, data) {
       axisTick: {
         show: false
       },
-      min:maxMin[1][1],
-      max:maxMin[1][0],
-      splitNumber:5,
-      interval: (maxMin[1][0]-maxMin[1][1])/5
+      min: 0,
+      max: max[1],
+      splitNumber: 5,
+      interval: max[1]/5
     }],
     series: data
   };
@@ -314,10 +314,7 @@ export function getMax(data) {
       d0 = d0.concat(item.data)
     }
   });
-  return [
-    [BASE.numberCeil(Math.max.apply(null,d0)), Math.min.apply(null,d0)], 
-    [BASE.numberCeil(Math.max.apply(null,d1)), Math.min.apply(null,d1)]
-  ]
+  return [BASE.numberCeil(Math.max.apply(null,d0)), BASE.numberCeil(Math.max.apply(null,d1))]
 }
 
 /*