I want to have a chart that resizes with the browser window, but the problem is that the height is fixed to 400px. This JSFiddle example has the same problem.
How can I do that? I tried using the chart.events.redraw event handler to resize the chart (using .setSize), but I guess it starts a never-ending loop (fire event handler, which calls setSize, which fires another event handler, etc.).
Height and width is set either by setting a height and width of the container div, or by setting the chart. height and chart. width Highcharts options.
Since Highcharts 5.0 you can create responsive charts much the same way you work with responsive web pages. A top-level option, responsive, exists in the configuration. One of the most handy options is chart. className that can be used to control the style of all other elements in Highcharts styled mode.
Yes, you can. You could add more. If you get stack with implementing your project, please send us a minimal, verifiable demo in JSFiddle, so we could help you out with your code.
Just don't set the height property in HighCharts and it will handle it dynamically for you so long as you set a height on the chart's containing element. It can be a fixed number or a even a percent if position is absolute.
Highcharts docs:
By default the height is calculated from the offset height of the containing element
Example: http://jsfiddle.net/wkkAd/149/
#container { height:100%; width:100%; position:absolute; }
What if you hooked the window resize event:
$(window).resize(function() { chart.setSize( $(document).width(), $(document).height()/2, false ); });
See example fiddle here.
Highcharts API Reference : setSize().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With