使用morris时出现js报错VM9763:10 Error: <text> attribute transform: Expected number, "matrix(NaN,NaN,

最近使用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();
            }
        };

我遇到的情况改写这段代码就可以解决,若还有问题可参考以下代码(未尝试)

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.

Morris.Donut.prototype.resizeHandler = function () {
    this.timeoutId = null;
    if (this.el && this.el.width() > 0 && this.el.height() > 0) {
        this.raphael.setSize(this.el.width(), this.el.height());
        return this.redraw();
    }
    else return null;
};
Morris.Donut.prototype.setData = function (data) {
    var row;
    this.data = data;
    this.values = (function () {
        var _i, _len, _ref, _results;
        _ref = this.data;
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            row = _ref[_i];
            _results.push(parseFloat(row.value));
        }
        return _results;
    }).call(this);
    if (this.el && this.el.width() > 0 && this.el.height() > 0) {
        return this.redraw();
    }
    else return null;
};

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:

Morris.Donut.prototype.setLabels = function(label1, label2) {
    var inner, maxHeightBottom, maxHeightTop, maxWidth, text1bbox, text1scale, text2bbox, text2scale;
    inner = (Math.min(this.el.width() / 2, this.el.height() / 2) - 10) * 2 / 3;
    maxWidth = 1.8 * inner;
    maxHeightTop = inner / 2;
    maxHeightBottom = inner / 3;
    this.text1.attr({
        text: label1,
        transform: ''
    });
    text1bbox = this.text1.getBBox();
    text1scale = Math.min(maxWidth / text1bbox.width, maxHeightTop / text1bbox.height);
    if (isNaN(text1scale) || text1scale == "-Infinity") {
        text1scale = "0.0";
    }
    this.text1.attr({
        transform: "S" + text1scale + "," + text1scale + "," + (text1bbox.x + text1bbox.width / 2) + "," + (text1bbox.y + text1bbox.height)
    });
    this.text2.attr({
        text: label2,
        transform: ''
    });
    text2bbox = this.text2.getBBox();
    text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height);
    if (isNaN(text2scale) || text2scale == "-Infinity") {
        text2scale = "0.0";
    }
    var t = {
        transform: "S" + text2scale + "," + text2scale + "," + (text2bbox.x + text2bbox.width / 2) + "," + text2bbox.y
    };
    return this.text2.attr(t);
};
解决方法引自morris的githab  https://github.com/morrisjs/morris.js/issues/420
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我无法回答关于"model:wj03"的问题。可以提供更多的上下文或者更具体的问题吗?这样我才能为您提供帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ahpmatlab代码-TCrelay-Morris-Lecar-model:我们研究了带有多个扩展的Morris-Lecar模型中的尖峰序列](https://download.csdn.net/download/weixin_38602098/19140751)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [主题模型TopicModel:Unigram、LSA、PLSA模型](https://blog.csdn.net/chuange6363/article/details/100752944)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [2019.01.11 应用结构 --》model-》最佳实践](https://blog.csdn.net/tangerine_/article/details/86301568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值