sandrowi
sandrowi

Reputation: 113

Only one gwt-chart visible

I'm trying to display multiple charts in a gwt-Project using the gwt-charts library but just the last created chart is visible no matter what layout or which widget I use.

TableExample is identical to this: http://gwt-charts.appspot.com/#table

Then add the charts to the main panel like this:

private DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.EM);
private TabLayoutPanel tabLayoutPanel = new TabLayoutPanel(1.5, Unit.EM);

@Override
public void onModuleLoad() {
    Window.enableScrolling(false);
    Window.setMargin("0px");

    tabLayoutPanel.add(new TableExample(), "Here should the first table be");
    tabLayoutPanel.add(new HTML("Lorem ipsum dolor sit amet"), "Lorem");
    tabLayoutPanel.add(new TableExample(), "Only visible table");
    tabLayoutPanel.add(new HTML("ga ga ga lalasdf a3ifa"), "Other text");

    mainPanel.add(tabLayoutPanel);
    RootLayoutPanel.get().add(mainPanel);

}

The two tabs with HTML and the second TableExample show the correct content but the first tab with the TableExample is empty.

Does anyone know why one only gwt-chart is visible? I don't get any error messages or something.

Upvotes: 1

Views: 226

Answers (1)

Dan G
Dan G

Reputation: 11

The problem is that TableExample draws the chart only after the Runnable is executed after the chart api is loaded. When you create two TableExamples they both try to load the chart api but only one of them succeeds and thus only one of the Runnables is called.

To fix it you need to load the chart api just once -- perhaps when your app first loads. Then TableExample can be changed to just draw itself without having to first load the api.

Upvotes: 1

Related Questions