morris js donut doesnt render in bootstrap tab

℡╲_俬逩灬. 提交于 2020-01-25 04:20:07

问题


I'm trying do display a morrisjs chart within a bootstrap tabbed page. I'm using the sample chart here: Donut Chart

When I place the <div id="example-donut"> outside of the bootstrap tabs, everything works. Once I place it inside a bootstrap tab

<div class="tabbable" id="tabs-936589">
  <div class="tab-content">
    <div class="tab-pane" id="mycharts">
      <div id="example-donut"></div>
    </div>
  </div>
</div>

I get the following error:

Error: Invalid value for <text> attribute transform="matrix(NaN,NaN,NaN,NaN,0,0)"

If I place it in the active tab, this works without any issues.

Anyone else hitting this same issue ?


回答1:


This worked for me:

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;
};


来源:https://stackoverflow.com/questions/34006159/morris-js-donut-doesnt-render-in-bootstrap-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!