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

Projects

None yet

2 participants

@matt-hoskins

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
Collaborator
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

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
Collaborator
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