arraylist - Can't Get Multiple Charts (Google Visualization) on Multiple Tabs (GWT TabPanel) -
i need display unknown quantity of tabs each unknown quantity of graphs (google visualizations). have created "tab" , "graph" classes , tab contains arraylist.
tabwrappers extends flextable , empty. it's place holder @ moment, behavior not change if use flextable rather tabwrapper.
the code below, minus section adds tab2 works creating 1 tab populated graphs. when adding 2nd tab both tabs displayed , named correctly neither have graphs.
public class someclass { ... datatable data = response.getdatatable(); dataview result; options options = createoptions(); arraylist<tab> displaytab = new arraylist<tab>(); tab t; arraylist<graph> graphlist = new arraylist<graph>(); graph g; t = new tab(); g = new graph(); result = dataview.create(data); result.setrows(new int[]{0, 2, 4, 6}); g.setgraphtype(new piechart(result, options)); graphlist.add(g); g = new graph(); result = dataview.create(data); result.setrows(new int[]{1, 3, 5, 7}); g.setgraphtype(new piechart(result, options)); graphlist.add(g); g = new graph(); result = dataview.create(data); g.setgraphtype(new piechart(result, options)); graphlist.add(g); t.settabname("tab1"); t.setgraphs(graphlist); displaytab.add(t); // add 2nd tab t = new tab(); t.settabname("tab2"); t.setgraphs(graphlist); displaytab.add(t); tabwrapper tabwrapper; (tab tx : displaytab){ int row = 0, col = 0, maxcol = 2; tabwrapper = new tabwrapper(); (graph gx : tx.getgraphs()) { col = tx.getgraphs().indexof(gx) - (row * maxcol); tabwrapper.setwidget(row, col, gx.getgraphtype().aswidget()); if (++col == maxcol) { row++; } } tabpanel.add(tabwrapper, tx.gettabname()); } ... }
when use tabs in gwt, panels held in each tab seem lazy loaded , aren't set until user clicks on each tab.
in particular, tab containers have 0 widths , heights (the error logs giving error containers having 0 width) graph drawing fail , leave empty space.
what need (and practice anyway) lazy load contents of tabs graph loaded when tab set up. can done removing call t.setgraphs(...) , adding selection handler instead:
tabpanel.addselectionhandler(new selectionhandler<integer> () { public void onselection(selectionevent<integer> event) { // pseudocode: // n = event.getselecteditem() // t = displaytab[n] // g = graphlist[n] // t.setgraphs(g) } });
so graphs added , drawn when tab selected.
you'll want call
tabpanel.selecttab(0);
to force selection of first tab after selection handler in place.
i had same issues describe , resolved it.
Comments
Post a Comment