When you open a chart inside the center zone of a DockLayoutPanel (inside a RootLayoutPanel), the first time the chart is rendered (possibly during onModuleLoad) the chart does not have the right height/width. The chart take the size of the RootLayoutPanel not the size of the center zone.
When you resize the browser window, the chart resizes correctly. Does anyone knows how to fix this ?
@Override
public void onModuleLoad()
{
RootLayoutPanel rootPanel = RootLayoutPanel.get();
Chart chart = createChart();
chart.setWidth100();
chart.setHeight100();
DockLayoutPanel dock1 = new DockLayoutPanel(Unit.PX);
SimpleLayoutPanel slp1 = new SimpleLayoutPanel();
slp1.getElement().getStyle().setBackgroundColor("blue");
SimpleLayoutPanel slp2 = new SimpleLayoutPanel();
slp2.getElement().getStyle().setBackgroundColor("yellow");
SimpleLayoutPanel slp3 = new SimpleLayoutPanel();
slp3.getElement().getStyle().setBackgroundColor("red");
SimpleLayoutPanel slp4 = new SimpleLayoutPanel();
slp4.getElement().getStyle().setBackgroundColor("green");
dock1.addNorth(slp1, 50);
// dock1.addSouth(slp3, 50);
dock1.addWest(slp2, 50);
// dock1.addEast(slp4, 50);
dock1.add(chart);
rootPanel.add(dock1);
}
For info i tried
chart.redraw();
rootPanel.forceLayout();
but it does not improve the situation
Github project example : https://github.com/mycom-int/gwthighcharts
Another option can be to extend Chart class and implement RequiresResize. In the onResize method schedule setSizeToMatchContainer().