I am currently working on creating a dynamic page that can display between 1-4 graphs. These graphs need to be able to resize when added or removed from the page. However, I have encountered a major issue with resizing the graphs after resizing the containing div. For example, if I add a graph to the page and then click a button to add another graph, each graph should resize to 400 pixels in width. Unfortunately, I have been unable to achieve this functionality. As a simplified version of my code, I have included the following:
$(function () {
$('#container').highcharts({
chart: {
type: 'line',
width: 300
},
title: {
text: 'Width is set to 300px'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
$('#resize').click(function() {
$('#container').attr('style', 'width: 800px');
$("#container").highcharts().reflow();
console.log($('#container').width());
});
});
When this code is executed, it logs 800 to the Chrome developer tools window, but the graph does not actually resize. I have attempted using both redraw() and reflow(), as recommended in the Highcharts documentation. I even created a quick demo on jsfiddle here, http://jsfiddle.net/7cbsV/. Can anyone offer assistance with this issue? Your help would be greatly appreciated. Thank you in advance.