Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize height with Highcharts

Tags:

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..     };     //... } 
like image 447
Joe Avatar asked Dec 07 '12 18:12

Joe


People also ask

How do I set height and width in highcharts?

use chart. setSize(width, height, doAnimation = true); in your actual resize function to set the height and width dynamically.

How do I resize a Highchart react?

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.

Is highcharts responsive?

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.

What is legend in highcharts?

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.


2 Answers

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:

  1. Set up a timed and pipelined resize event listener. Example with 500ms on jsFiddle
  2. use chart.setSize(width, height, doAnimation = true); in your actual resize function to set the height and width dynamically
  3. Set reflow: 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.
like image 197
Philzen Avatar answered Sep 18 '22 09:09

Philzen


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

  • http://api.highcharts.com/highstock#chart.height
  • http://api.highcharts.com/highstock#chart.events.redraw
like image 27
Ricardo Alvaro Lohmann Avatar answered Sep 22 '22 09:09

Ricardo Alvaro Lohmann