Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Calling this.destroy in a load callback leads to "this.options is undefined" in Chart.prototype.onload #6068
This is the piece of code in onload that triggers the issue:
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.:
No exception if calling this.destroy() in a load callback
"this.options is undefined" exception if calling this.destroy() in a load callback
Live demo with steps to reproduce
You'll see an error on your debug console from Chart.prototype.onload
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):