I have a Highchart which resizes the width beatuifully when the window change size. But not the height. I tried this set chart size but it's not working proberly. Is there any other way to automatically change the height when window change size?
This is my css code for the output. I have a Jquery UI tab, the other tab is showing the datatable
#output-container { float: right; display: inline; position: absolute; right: 10px; left: 400px; top:120px; overflow-y: auto; }
This is my css for the chartdiv:
#chartContainer{ margin: auto; }
And this is the js Chart function:
function qchart(){ chart = new Highcharts.Chart({ chart: { renderTo: 'chartContainer', type: 'column', spacingBottom: 3, //height: (screen.availHeight)-500, marginRight: 30, marginBottom: 30, reflow: true }, //etc.. }; //... }
use chart. setSize(width, height, doAnimation = true); in your actual resize function to set the height and width dynamically.
Use the highcharts-react-official package (>= 2.1) and set containerProps={{ style: { height: "100%" } }} . This will make the chart dynamically resize to fill its parent div. You can then set up parent divs using flexbox to get your desired layout.
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.
The legend displays the series in a chart with a predefined symbol and the name of the series. Series can be disabled and enabled from the legend.
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:
chart.setSize(width, height, doAnimation = true);
in your actual resize function to set the height and width dynamicallyreflow: false
in the highcharts-options and of course set height
and width
explicitly on creation. As we'll be doing our own resize event handling there's no need Highcharts hooks in another one.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
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