djkloop commented on issue #10887: 如何获取yAxis里面的最大值?
URL: 
https://github.com/apache/incubator-echarts/issues/10887#issuecomment-513850182
 
 
   @Ovilia 多谢回复
   在源码中找到了... 把那个方法copy了出来了...
   不过感觉这个可以加个api获取一下...
   
   ```
   window.onload = function () {
     document.write('加载完成');
   
   
     let extendVal = [];
   
   
     let dataExtend = [0, 2006];
     let dataExtend1 = [0, 2000];
     let dataExtend2 = [0, 3381];
     let interval = 0;
   
     createNumber(dataExtend2)
   }
   
   function createNumber (dataExtend) {
     const splitNumber = 4;
     const result = Interval(dataExtend, splitNumber, undefined, undefined);
     const { interval } = result;
   
   
   
     // fixMin
     const minVal = Util.round(Math.floor(dataExtend[0] / interval) * interval);
   
     // fixMax
     const maxVal = Util.round(Math.ceil(dataExtend[1] / interval) * interval);
   
     console.log([minVal, maxVal]);
   }
   
   
   function Interval (extent, splitNumber, minInterval, maxInterval) {
     const result = {};
     var span = extent[1] - extent[0];
     var interval = result.interval = Util.nice(span / splitNumber, true);
   
   
     if (minInterval != null && interval < minInterval) {
       interval = result.interval = minInterval;
     }
     if (maxInterval != null && interval > maxInterval) {
       interval = result.interval = maxInterval;
     } // Tow more digital for tick.
   
     result.interval = interval;
     return result;
   }
   
   // 辅助 - Interval - 函数
   function quantityExponent (val) {
     return Math.floor(Math.log(val) / Math.LN10);
   }
   
   class Util {
     static nice (val, round) {
       var exponent = quantityExponent(val);
       var exp10 = Math.pow(10, exponent);
       var f = val / exp10; // 1 <= f < 10
   
       var nf;
   
       if (round) {
         if (f < 1.5) {
           nf = 1;
         } else if (f < 2.5) {
           nf = 2;
         } else if (f < 4) {
           nf = 3;
         } else if (f < 7) {
           nf = 5;
         } else {
           nf = 10;
         }
       } else {
         if (f < 1) {
           nf = 1;
         } else if (f < 2) {
           nf = 2;
         } else if (f < 3) {
           nf = 3;
         } else if (f < 5) {
           nf = 5;
         } else {
           nf = 10;
         }
       }
   
       val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 
754).
       // 20 is the uppper bound of toFixed.
   
       console.log(val, '  -> val');
       console.log(exponent, '  -> exponent');
       console.log(exp10, '  -> exp10');
       console.log(f, '  -> f');
       console.log(nf, '  -> nf');
       console.log(val, '  -> val');
   
       return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : 
val;
     }
   
   
     static round(x, precision, returnStr) {
       if (precision == null) {
         precision = 10;
       }
   
       precision = Math.min(Math.max(0, precision), 20);
       x = (+x).toFixed(precision);
       return returnStr ? x : +x;
     }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to