Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts - issue about full chart width

I'm using Highcharts column chart and I want it to be 100% width responsive chart. The container is a simple <div> with no any formatting. When the document loads, the chart is always fixed width 600x400px size. If I resize window or switch to another browser tab, the chart fills the width and becomes responsive full width chart just like I wanted. If I reload page, it's fixed width again. I tried setting width to both container and chart, however, nothing helps. If I move the container div one level above the parent div, It works. How to make the chart become full width on page load also?

Thanks

like image 205
Deez Avatar asked May 08 '13 09:05

Deez


People also ask

How do I change the width and height of a Highchart?

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

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.

How do I set margins in Highcharts?

margin: number, Array. The margin between the outer edge of the chart and the plot area. The numbers in the array designate top, right, bottom and left respectively. Use the options marginTop , marginRight , marginBottom and marginLeft for shorthand setting of one option. By default there is no margin.


2 Answers

Chart's width is taken from jQuery.width(container), so if you have chart in some hidden tabs or something similar, width will be undefined. In that case default width and height are set (600x400).

like image 154
Paweł Fus Avatar answered Sep 29 '22 12:09

Paweł Fus


I know this is an old question, but I ran into the exact same issue and found another solution that works great.

As of Highcharts 4.1.5 (could be in older versions as well), the chart object has a reflow() function. View the documentation here.

reflow ()

Reflows the chart to its container. By default, the chart reflows automatically to its container following a window.resize event, as per the chart.reflow option. However, there are no reliable events for div resize, so if the container is resized without a window resize event, this must be called explicitly.

Hope it helps someone else.

like image 36
cohenadair Avatar answered Sep 29 '22 11:09

cohenadair