最近使用morris,发现老是出现js报错,
版本morris.min.js v0.5.0
VM9763:10 Error: <text> attribute transform: Expected number, "matrix(NaN,NaN,
查到原因为关闭窗口时,morris仍然调用resizeHandler方法进行画图,由于窗口已经关闭,图肯定画不出来,自然就要报错.
解决方法:
找到对应方法修改源代码
Morris.Donut.prototype.resizeHandler = function() {
if (this.el && this.el.width() > 0 && this.el.height() > 0) {
this.timeoutId = null;
this.raphael.setSize(this.el.width(), this.el.height());
return this.redraw();
}
};
我遇到的情况改写这段代码就可以解决,若还有问题可参考以下代码(未尝试)
HelloGravity commented
on Jun 16 2014
Thank you for your solution heyGalen !
I am having the same error :
Error: Invalid value for attribute transform="matrix(NaN,NaN,NaN,NaN,0,0)"
And I am also not familiar with the source code of Morris.
Although your solution did not work for me, I changed it a little, and now everything works for me, thanks.
BTW, morris.js is awesome :)
Hello there, for me the error was elsewhere, as part of the "setLabels" handler. The fix was to handle the case where "text1" or "text2" were NaN: