NedStarkOfWinterfell
NedStarkOfWinterfell

Reputation: 5243

Highstock chart doesn't show after it has been cleared

I am trying to make a simple page where there will be a Highstock chart on page-load and two buttons, one for removing the graph and another for reloading it. However, once the first button has been clicked to clear the container of the chart inside, subsequent clicks on the 2nd button doesn't reload the chart. How can I reload it? The fiddle is at http://jsfiddle.net/Cupidvogel/DCkmN/

Upvotes: 0

Views: 290

Answers (2)

Jugal Thakkar
Jugal Thakkar

Reputation: 13482

If you debug, you see that the chartingOptions isn't getting cleared. It's series property is becoming null immediately after constructor's call. Seems like a bug to me. Or may be its intended to avoid cloning the huge data that is included in the series option, and just use the same object over for charting.

This is what the source code says,

 userOptions.series = null; 

the userOptions.series property is purposely being set to null after being copied over for construction.

    /**
    * The chart class
    * @param {Object} options
    * @param {Function} callback Function to run when the chart has loaded
    */
    function Chart(userOptions, callback) {
    // Handle regular options
    var options,
    seriesOptions = userOptions.series; // skip merging data points to increase performance
    userOptions.series = null;  

Upvotes: 1

Matt Razza
Matt Razza

Reputation: 3654

You're losing your chart options array when you clear it for some reason. You can just create it in the function itself like this.

Or better yet move it into it's own function so you can reuse it like this.

Upvotes: 3

Related Questions