0
votes

Using latest HighStock/HighCharts we are creating charts with this syntax:

$('#container').highcharts({...

We then allow the user to do some manipulation of the chart series displayed. We added the ability for the user to reset the chart back to how it was originally. We are using this method:

function forceResetChart(chart) {
    var opts = chart.options;
    chart.destroy();
    chart = new Highcharts.Chart(opts);
}

This does reset the chart and we are able to make changes again. However, we are keep getting errors thrown in the console:

TypeError: a.renderTo is undefined @ .../JavaScript/HighStock/highstock.js:198

How can we still use the cleaner syntax ($('#container').highcharts({...) and not get this error thrown?

Example jsFiddle.

1

1 Answers

2
votes

option 1) Just make sure you still specify "renderTo:'container'" in the chart properties. Or, if you don't want to include in the initial chart code, add it to the options in your forceReset function.

option 2) in your forceReset function, use the same '$('#container').Highcharts...' syntax to call your chart, rather than switching back to the other syntax

example of option 2: 

http://jsfiddle.net/5pa7N/8/

{{edit option 3:

  • set options variable up front.
  • call chart on page load using that variable.
  • reload chart using that variable

http://jsfiddle.net/eYmh9/