• echarts 通过源码方法 传入对应data数据获取分割步长值


     通过源码方法获取这里的分割数字长度

    /**
     * Quantity of a number. e.g. 0.1, 1, 10, 100
     *
     * @param  {number} val
     * @return {number}
     */
    function quantity(val) {
        return Math.pow(10, quantityExponent(val));
    }
    
    function quantityExponent(val) {
        return Math.floor(Math.log(val) / Math.LN10);
    }
    
    /**
     * find a “nice” number approximately equal to x. Round the number if round = true,
     * take ceiling if round = false. The primary observation is that the “nicest”
     * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
     *
     * See "Nice Numbers for Graph Labels" of Graphic Gems.
     *
     * @param  {number} val Non-negative value.
     * @param  {boolean} round
     * @return {number}
     */
    function nice(val, round) {
      console.log('get real splitNum==1111===>', 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.
      const nice = exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
        return nice;
    }
    

      

    使用方法

    // val 传递的是: (你当前data数组中的最大值 / (splitNumber | 5))
    // splitNumber 是你写的分割段数 如果没有设置 则使用5相除 
    // round 传false
    
    
    // 例如 我这里传24
    nice(24,false); // 返回20, 其中20 就是 步长值

    // 如果是堆叠图表 需要进行数据相加后 获取相加后的数组的最大值 然后进行计算
    nice(37, false); //

      

  • 相关阅读:
    Windows Phone开发(29):隔离存储C 转:http://blog.csdn.net/tcjiaan/article/details/7447469
    Windows Phone开发(25):启动器与选择器之WebBrowserTask 转:http://blog.csdn.net/tcjiaan/article/details/7404770
    内存知识集
    牛人榜
    如何解决SQL Server 2000 中的连接问题(邹建)
    索引
    .net事件机制
    内核对象
    使用socket tcp实现通讯
    sql技巧
  • 原文地址:https://www.cnblogs.com/MainActivity/p/11511395.html
Copyright © 2020-2023  润新知