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

Calling this.destroy in a load callback leads to "this.options is undefined" in Chart.prototype.onload #6068

Closed
matt-hoskins opened this Issue Dec 1, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@matt-hoskins

matt-hoskins commented Dec 1, 2016

This is actually similar to #3600 in underlying cause but caused by a bit of code added subsequent to #3600 being fixed.

This is the piece of code in onload that triggers the issue:

                // Set up auto resize
                if (this.options.chart.reflow !== false) {
                    this.initReflow();
                }

If this.destroy() was called in one of the callbacks run prior to this point then this.options is undefined - so a similar check to the one done when fixing #3600 should do the job, e.g.:

                // Set up auto resize
                if (this.index !== undefined && this.options.chart.reflow !== false) {
                    this.initReflow();
                }

Expected behaviour

No exception if calling this.destroy() in a load callback

Actual behaviour

"this.options is undefined" exception if calling this.destroy() in a load callback

Live demo with steps to reproduce

http://jsfiddle.net/phh0a7w0/2/

You'll see an error on your debug console from Chart.prototype.onload

Affected browser(s)

Any

@pawelfus

This comment has been minimized.

Show comment
Hide comment
@pawelfus

pawelfus Dec 1, 2016

Contributor

Thanks for reporting the issue!

However, could explain the purpose of using chart.destroy() right after chart was created?

Contributor

pawelfus commented Dec 1, 2016

Thanks for reporting the issue!

However, could explain the purpose of using chart.destroy() right after chart was created?

@pawelfus pawelfus added the Bug label Dec 1, 2016

@matt-hoskins

This comment has been minimized.

Show comment
Hide comment
@matt-hoskins

matt-hoskins Dec 1, 2016

I'm essentially rendering a dummy chart with a subset of data to find out what space Highchart would allocate for the categories and axis label on the left and the legend on the right - I basically take the plotLeft and plotWidth values from that dummy chart and destroy it. I'm then using those values as part of creating the actual chart I want in the same container - chart which is akin to the demographics chart but with the categories and axis lines in the middle separating the two sides - I use the plotLeft and plotWidth from the dummy chart to set offsetLeft and offsetRight on the pairs of x and y axis for the chart I then create (which has the same categories and legend - but only draws the categories on one of the pairs of x axis).

It's an ugly solution to figuring out what size areas Highcharts thinks are needed for the legend and categories for a given chart spec and data set - there may be a more elegant one but I've only been using Highcharts for a week so I'm still doing a lot of learning about it (I'm evaluating it to see if I can recreate a set of existing charts rendered in a different server-side charting library before deciding whether to proceed further with using it!).

Anyway this is what I end up with (I've blurred the categories as they're company names):

chartpair-6068

matt-hoskins commented Dec 1, 2016

I'm essentially rendering a dummy chart with a subset of data to find out what space Highchart would allocate for the categories and axis label on the left and the legend on the right - I basically take the plotLeft and plotWidth values from that dummy chart and destroy it. I'm then using those values as part of creating the actual chart I want in the same container - chart which is akin to the demographics chart but with the categories and axis lines in the middle separating the two sides - I use the plotLeft and plotWidth from the dummy chart to set offsetLeft and offsetRight on the pairs of x and y axis for the chart I then create (which has the same categories and legend - but only draws the categories on one of the pairs of x axis).

It's an ugly solution to figuring out what size areas Highcharts thinks are needed for the legend and categories for a given chart spec and data set - there may be a more elegant one but I've only been using Highcharts for a week so I'm still doing a lot of learning about it (I'm evaluating it to see if I can recreate a set of existing charts rendered in a different server-side charting library before deciding whether to proceed further with using it!).

Anyway this is what I end up with (I've blurred the categories as they're company names):

chartpair-6068

@pawelfus

This comment has been minimized.

Show comment
Hide comment
@pawelfus

pawelfus Dec 1, 2016

Contributor

Thanks for the explanation! We really appreciate that :)

Contributor

pawelfus commented Dec 1, 2016

Thanks for the explanation! We really appreciate that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment