Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'chart' of undefined at a.Chart.reflow #75

Closed
olomakovskyi opened this issue Aug 30, 2017 · 12 comments
Closed

Comments

@olomakovskyi
Copy link

Hi,
I have a single page angular application which contains few charts. When it starts to load charts specified errors are appear in console:

ERROR TypeError: Cannot read property 'chart' of undefined
    at a.Chart.reflow (eval at webpackJsonp.79.module.exports (addScript.js:9), <anonymous>:251:193)
    at ng2-highcharts-base.js:28
    at ZoneDelegate.invokeTask (zone.js:398)
    at Object.onInvokeTask (core.es5.js:4140)
    at ZoneDelegate.invokeTask (zone.js:397)
    at Zone.runTask (zone.js:165)
    at ZoneTask.invoke (zone.js:460)
    at timer (zone.js:1732)

as I can see from debugger, error appears in function reflow() in ng2-highcharts-base.js
ng2_highcharts
it calls function reflow() of highcharts and then falls with exception because this.options is undefined
highcharts

Could you please advice what might be the cause of it?

@Bigous
Copy link
Owner

Bigous commented Aug 30, 2017

What's the class that you are using ? Did you follow the wiki example ?

@olomakovskyi
Copy link
Author

I use import {Ng2HighchartsModule} from 'ng2-highcharts'; as was described in wiki.
I've also found similar issue described for highcharts-ng pablojim/highcharts-ng#594
I understand that libs are different, but since the both are related to highcharts, may be it caused by similar problem. And last commentator mentioned that he also faced with such issue using ng2-highcharts.

@Bigous
Copy link
Owner

Bigous commented Sep 4, 2017

@sephh You are the heavier user of this library. Could you give us a light?

@chriszrc
Copy link

I just ran into this problem as well. It started when I changed the parent component's change detection strategy to OnPush (that's the parent of the component in which I actually use the ng-highmaps directive).

After trying a few things, I added:

changeDetection: ChangeDetectionStrategy.OnPush

Not just to the parent, but also to the component with the highchart, and then everything returned to normal.

@chriszrc
Copy link

chriszrc commented Sep 19, 2017

Hmm, I think I did have it happen again, but it's much more rare now. The problem does seem to lie here:

 Ng2HighchartsBase.prototype.reflow = function () {
        var _this = this;
        if (!this.pChart || !this.options) {
            return;
        }
        if (getComputedStyle(this.hostElement.nativeElement).transitionDuration) {

var duration = parseFloat(getComputedStyle(this.hostElement.nativeElement).transitionDuration);

            var interval = setInterval(function () {
                if (duration < 0) {
                    clearInterval(interval);
                }
                _this.pChart.reflow();
                duration -= 50;
            }, duration);
        }
        this.pChart.reflow();
    };

Sometime the bold line tries to get the transitionDuration, but it fails because there is no longer any this.hostElement. A simple check there I think would solve this problem

@Bigous
Copy link
Owner

Bigous commented Sep 27, 2017

Hi @chriszrc ,

If that is the case, it should stop in the if, one line before the parse, not?

[]'s

@chriszrc
Copy link

chriszrc commented Sep 27, 2017 via email

mattlewis92 added a commit to mattlewis92/ng2-highcharts that referenced this issue Oct 11, 2017
mattlewis92 added a commit to mattlewis92/ng2-highcharts that referenced this issue Oct 11, 2017
@Bigous Bigous closed this as completed in #82 Nov 3, 2017
Bigous added a commit that referenced this issue Nov 3, 2017
… deleted.

To provide some "beaultiful" resize UX, reflow is called each 50ms when resizing the component. When
there is a resize and and a destroy, the setInterval could call reflow on an invalid object.

Closes #75, #82
@AbdurRehman91
Copy link

Hi.I am facing this exactly same issue.Can you kindly update me on this?

@Bigous
Copy link
Owner

Bigous commented Dec 8, 2017

Can you post the stack trace?

@Bigous
Copy link
Owner

Bigous commented Dec 8, 2017

And the version of ng2-highcharts that you are using

@EricCronje
Copy link

Was this resolved? Same issue here

@Mythrim
Copy link

Mythrim commented Oct 3, 2019

Does this issue is resolved, I am still facing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants