question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot read property 'modLayer' of null

See original GitHub issue

image

function reloadEcharts(obj, json) {
    var chart = echarts.init(obj);
    chart.setOption(json);
    window.addEventListener("resize", function() {
        chart && chart.resize();
    });
}

开启chrome 调试台时候,会触发echarts resize 事件,会引起报错,望解惑…

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
thanatos11commented, Oct 28, 2015

The problem is based on the new ajax chart, will delete the old one, the system tries to resize the old one, but that no longer exists. One solution is to bind the function to resize and unbind after the new ajax and bind again. But this is also a problem, because the binding is done on unanimous function. So this implementation helped me:

I. define a new modules.js inside the “echarts/module/modules.js”

II. inside the modules.js define a new require dict holding all your charts:

define(function(){
    var charts = {
        'Chart1':false,
        'Chart2': false,
        'Chart3' : false
    };
    $(window).resize(function(){
         if ( charts['Chart1'] ) {
            charts['Chart1'].resize();
        }
         if ( charts['Chart2'] ) {
            charts['Chart2'].resize();
        }
         if ( charts['Chart3'] ) {
            charts['Chart3'].resize();
        }
    });
    return function(k){ charts[k["name"]] = k["content"] }
});

III. In your chart function just call the new module with the require.js:

require(
        [   'echarts',
            'echarts/chart/line',
            'echarts/module/modules'
        ], function (ec, line, modules) {
            var Chart1 = ec.init(document.getElementById('chart_1'));
            modules({ "name" : "Chart1", "content" : Chart1});
            var chart_1_option = {.....}
....... etc
2reactions
wzhscriptcommented, Nov 3, 2015

我也遇到了这个问题。原因应该是:window.onresize上绑定的resize方法所对应的chart对象已经不存在了。 所以在调用echarts.init后也要更新window.onresize对应的resize方法。(如果是用jquery.on绑定resize函数,相应也需要用jquery.off去解除绑定)

var myChart = echarts.init(someDOMElement);
window.onresize = myChart.resize;

// or

var myChart = echarts.init(this.refs.container.getDOMNode());
global._preResize && $(window).off('resize', global._preResize);
global._preResize = myChart.resize;
$(window).on('resize', myChart.resize);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of null - iDiallo
This will result in Uncaught TypeError: Cannot read property 'value' of null . The reason will be that the element with id input...
Read more >
Uncaught TypeError: Cannot read property 'modLayer' of null ...
I have the same error. Is there any fix? This happens when I call back a new chart from Ajax, then the resize...
Read more >
Uncaught TypeError: Cannot read property of null
Hello im having trouble of fixing this error Uncaught TypeError: Cannot read property '2' of null . This is what i want to...
Read more >
Re: TypeError: Cannot read properties of null (rea...
Hello, I'm working with the ArcGIS API for Javascript, @arcgis/core ^4.22 inside an angular (13.1.1) application and encountering an error ...
Read more >
Cannot read property 'lat' of null - when 'Edit layer' option is ...
Uncaught TypeError : Cannot read property 'lat' of null at Object.project at Object.latLngToPoint at NewClass.project at NewClass.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found