How to revert/reverse/undo setSize() in Highcharts

106 views Asked by At

Question asked because I spent a while trying to solve this and the answer isn't easily Google-able:

If I've manually set the size of a chart how do I make it go back to how it was before I did so? (Question left deliberately ambiguous as I have found two distinct answers).

1

There are 1 answers

0
Brondahl On BEST ANSWER

You might want to do one of 2 things:

  1. Go back to the previous fixed size.

  2. Go back to the size being variable according the size of the containing element.

For #1, you can collect (and thus store for later resetting) the current size of the chart BEFORE you call the setSize() by calling chart.chartHeight or chart.chartWidth (where var chart = $('#chart-container').highcharts();), then just call setSize() again with the original values.

For #2, after you've called setSize() post-print, the chart will no-longer auto-size itself if the window changes. You can fix that by using the 'hack' detailed here: Is modifying chart.hasUserSize a bad idea after calling Chart.setSize()? Which consists of setting chart.hasUserSize = false;