score:39
Ricardo's answer is correct, however: sometimes you may find yourself in a situation where the container simply doesn't resize as desired as the browser window changes size, thus not allowing highcharts to resize itself.
This always works:
- Set up a timed and pipelined resize event listener. Example with 500ms on jsFiddle
- use
chart.setSize(width, height, doAnimation = true);
in your actual resize function to set the height and width dynamically - Set
reflow: false
in the highcharts-options and of course setheight
andwidth
explicitly on creation. As we'll be doing our own resize event handling there's no need Highcharts hooks in another one.
score:1
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!)
score:12
You must set the height of the container explicitly
#container {
height:100%;
width:100%;
position:absolute;
}
score:17
According to the API Reference:
By default the height is calculated from the offset height of the containing element. Defaults to null.
So, you can control it's height
according to the parent div using redraw
event, which is called when it changes it's size.
References
Source: stackoverflow.com
Related Query
- Resize height with Highcharts
- How to scale Highcharts height on window resize with React
- Resize data points with highcharts
- Resize a chart before printing with Highcharts
- Highcharts - Global configuration with common code and unique data & Headings
- Change height of Highcharts with JavaScript. By default only re-sizes on window re-size
- Resize issue while gridster.js with highcharts
- Gauge highcharts is not resize with ionic 2
- How to match columns height with spline in Highcharts
- passing formatting JavaScript code to HighCharts with JSON
- how to resize custom button's width and height in highcharts
- Highcharts multiple x axis and yaxis. The width of the 1st x-axis is not in sync with browser resize
- Highcharts chart keep increasing its height on browser resize
- Highcharts series visibility with csv data source
- Highcharts Angular - How to set chart width and height with percentages?
- How to have multiple highcharts with different series data in vuejs without repeating code
- Highcharts value bars with full height background bars
- Why code of Horizonal line(y-axis) on a single in Highcharts get applied to all other charts integrated with Webdatarocks
- Highcharts cloud issue with data source when duplicating chart
- error with adjusting height of pie chart using highcharts
- Getting numbers on Y-axis to show up as percentages with code from a Highcharts code generator tool?
- Highcharts dynamic height with table layout
- Update datalabel position after Heatmap resize with Highcharts
- Highcharts - init with different vertical/horizontal config based on browser width, also after resize
- Highcharts code with same set of code/data works in PHP but does not work in JSfiddle
- Highcharts - how can a chart with multi pies change container height automatic?
- Responsive Highcharts not sizing correctly until window resize
- Reload chart data via JSON with Highcharts
- Highcharts - how to have a chart with dynamic height?
- Styling bar colors in Highcharts with a gradient issue
More Query from same tag
- Highcharts : Shared Tooltip for non-matching x values
- Format Highcharts y-axis labels
- How to disable the on-hover color change in Highcharts?
- Add Source to Highcharts Export CSV
- Highcharts Stacked Range z-Index
- How to synchronize the From To date wrapper in Highstock?
- How to pass array in highchart ??
- highchart tooltip with multiple additional data in tooltip?
- Draw only part of data in Highcharts
- Highcharts not zooming series using option Highcharts.Series.prototype.drawPoints = function() { }
- Vue project: object does not support this property or method "hasOwnProperty" IE11
- How to add Legend in highchart compare stock chart
- Highcharts X-range. Columns of maximum height
- Responsive behaviour for ng-highcharts with compiled ng-click on xAxis labels hidden on load
- highcharts - How do I show/hide secondary y axis based on optional parameter
- RoR, Javascript - how to automatically update charts from table?
- How to fix the width of bar in waterfall chart as well as its x-axis width of one group.?
- highcharts, how to prevent series hover event to cause hover event on nearest point(marker)
- Highcharts area fillOpacity do not work when changing the color
- Customize Highcharts xaxis label
- Can we increase the height of tooltip anchor in Highcharts
- Highstock: how to define and make the x and y axes visible?
- Highcharts Legend event click to get data
- Highcharts stacked bar negative / positive total
- r- how to display the labels on the highcharter objects all the time
- Adding Series during componentWillReceiveProps does not work
- Highcharts : How to increase marker radius based on the value range in Y axis in Scatter Graph?
- Color x , y Plotbands highcharts
- change the color of Highmap
- Highcharts sankey diagram, series color