Menu

RootLayoutPanel autoresize chart and chart height

2013-11-05
2015-06-16
  • Ronan Quillevere

    The title of this post is not right but I cannot edit it or delete it sorry.

    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);
    }
    

    Github project example : https://github.com/mycom-int/gwthighcharts

    Created the same question in stackoverflow http://stackoverflow.com/questions/19807079/gwt-highcharts-auto-resize-width-and-height-in-layout-panel

     

    Last edit: Ronan Quillevere 2013-11-06
  • Ronan Quillevere

    The only sloution I found so far is to use a scheduler after the dock is added to rootpanel

      Scheduler scheduler = Scheduler.get();
      scheduler.scheduleDeferred(new ScheduledCommand()
      {
    
         @Override
         public void execute()
         {
            chart.setSizeToMatchContainer();
         }
      });
    
     
  • Chris Rooney

    Chris Rooney - 2015-06-16

    Thank you! I've been experiencing the same problem 18 months later.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.