echarts 遇到的坑

1.图表得宽度100px

参考源码:

Painter.prototype._getWidth = function() {
        var root = this.root;
        var stl = root.currentStyle || document.defaultView.getComputedStyle(root);
        return ((root.clientWidth || parseInt(stl.width, 10)) - parseInt(stl.paddingLeft, 10) - parseInt(stl.paddingRight, 10)).toFixed(0) - 0;
    };

echarts绘制图表计算宽度的时候,由于在当前页面获取不到元素,即display: none; 所以无法获取到clientWidth,而 parseInt(stl.width, 10)) 将 100%;转为100,所以计算出的图表宽度为100px。

解决方法:一个是设置固定宽度,一个是使用懒加载,在点击切换到相对应的页面时再渲染

2.计算百分比出现NaN%

 简单来说,就是返回得数据为0,累加计算的和为0,计算百分比时分母为0导致的。(分母不能为0)

参考链接:https://www.cnblogs.com/hanhanours/p/11977863.html

原文地址:https://www.cnblogs.com/cuipingzhao/p/15399029.html