I had a similar problem with height except my chart was inside a bootstrap modal popup, which I'm already controlling the size of with css. However, for some reason when the window was resized horizontally the height of the chart container would expand indefinitely. If you were to drag the window back and forth it would expand vertically indefinitely. I also don't like hard-coded height/width solutions.
So, if you're doing this in a modal, combine this solution with a window resize event.
// from link
$('#ChartModal').on('show.bs.modal', function() {
$('.chart-container').css('visibility', 'hidden');
});
$('#ChartModal').on('shown.bs.modal.', function() {
$('.chart-container').css('visibility', 'initial');
$('#chartbox').highcharts().reflow()
//added
ratio = $('.chart-container').width() / $('.chart-container').height();
});
Where "ratio" becomes a height/width aspect ratio, that will you resize when the bootstrap modal resizes. This measurement is only taken when he modal is opened. I'm storing ratio as a global but that's probably not best practice.
$(window).on('resize', function() {
//chart-container is only visible when the modal is visible.
if ( $('.chart-container').is(':visible') ) {
$('#chartbox').highcharts().setSize(
$('.chart-container').width(),
($('.chart-container').width() / ratio),
doAnimation = true );
}
});
So with this, you can drag your screen to the side (resizing it) and your chart will maintain its aspect ratio.
Widescreen
vs smaller
(still fiddling around with vw units, so everything in the back is too small to read lol!)