* Creates a table and a view and shows both next to each other.
*
* @return a panel with two tables.
*/
private Widget createDataView() {
Panel panel = new HorizontalPanel();
DataTable table = DataTable.create();
/* create a table with 3 columns */
table.addColumn(ColumnType.NUMBER, "x");
table.addColumn(ColumnType.NUMBER, "x * x");
table.addColumn(ColumnType.NUMBER, "sqrt(x)");
table.addRows(10);
for (int i = 0; i < table.getNumberOfRows(); i++) {
table.setValue(i, 0, i);
table.setValue(i, 1, i * i);
table.setValue(i, 2, Math.sqrt(i));
}
/* Add original table */
Panel flowPanel = new FlowPanel();
panel.add(flowPanel);
flowPanel.add(new Label("Original DataTable:"));
Table chart = new Table();
flowPanel.add(chart);
chart.draw(table);
flowPanel = new FlowPanel();
flowPanel.add(new Label("DataView with columns 2 and 1:"));
/* create a view on this table, with columns 2 and 1 */
Table viewChart = new Table();
DataView view = DataView.create(table);
view.setColumns(new int[] {2, 1});
flowPanel.add(viewChart);
panel.add(flowPanel);
viewChart.draw(view);
return panel;
}