Example usage for com.google.gwt.visualization.client DataTable addColumn

List of usage examples for com.google.gwt.visualization.client DataTable addColumn

Introduction

In this page you can find the example usage for com.google.gwt.visualization.client DataTable addColumn.

Prototype

private native int addColumn(String type, String label) ;

Source Link

Usage

From source file:cmg.org.monitor.module.client.InviteUser.java

License:Open Source License

/**
 * Creates the data list system./*  www  .  ja  v  a 2  s. c  om*/
 *
 * @param result the result
 * @param filter the filter
 * @return the abstract data table
 */
public static AbstractDataTable createDataListSystem(List<InvitedUser> result, String filter) {
    DataTable dataListUser = DataTable.create();
    dataListUser.addColumn(ColumnType.STRING, "USERNAME");
    dataListUser.addColumn(ColumnType.STRING, "STATUS");
    dataListUser.addColumn(ColumnType.STRING, "ACTION");
    List<InvitedUser> listTemp = new ArrayList<InvitedUser>();
    if (filter.equalsIgnoreCase(defaultFilter)) {
        for (InvitedUser u : result) {
            listTemp.add(u);
        }
    } else {
        for (InvitedUser u : result) {
            if (u.getStatus().equalsIgnoreCase(filter)) {
                listTemp.add(u);
            }
        }
    }
    if (listTemp.size() > 0) {
        dataListUser.addRows(listTemp.size());
        for (int i = 0; i < listTemp.size(); i++) {
            InvitedUser u = listTemp.get(i);
            dataListUser.setValue(i, 0, "<div style=\"min-width:450px\">" + u.getEmail() + "</div>");
            if (u.getStatus().equalsIgnoreCase(filter_Active)) {
                String status = "<a style=\"margin-left:auto;margin-right:auto;\" class=\"stt_userActive\" title=\""
                        + filter_Active + "\"/>";
                dataListUser.setValue(i, 1, "<div style=\"min-width:450px\">" + status + "</div>");
                String html = HTMLControl.getButtonForActiveUser(u);
                dataListUser.setValue(i, 2, "<div style=\"min-width:220px\">" + html + "</div>");
            }
            if (u.getStatus().equalsIgnoreCase(filter_requesting)) {
                String status = "<a style=\"margin-left:auto;margin-right:auto;\" class=\"stt_inactive\" title=\""
                        + filter_requesting + "\"/>";
                dataListUser.setValue(i, 1, "<div style=\"min-width:450px\">" + status + "</div>");
                String html = HTMLControl.getButtonForRequestingUser(u);
                dataListUser.setValue(i, 2, "<div style=\"min-width:220px\">" + html + "</div>");
            }
            if (u.getStatus().equalsIgnoreCase(filter_pending)) {
                String status = "<a style=\"margin-left:auto;margin-right:auto;\" class=\"stt_pending\" title=\""
                        + filter_pending + "\"/>";
                dataListUser.setValue(i, 1, "<div style=\"min-width:450px\">" + status + "</div>");
                String html = HTMLControl.getButtonForPendingUser(u);
                dataListUser.setValue(i, 2, "<div style=\"min-width:220px\">" + html + "</div>");
            }
        }
    }

    return dataListUser;
}

From source file:com.chap.links.client.GraphDemo1_basic_usage.java

License:Apache License

/**
 * This is the entry point method.//w  w w.  ja v a 2  s .c  om
 */
public void onModuleLoad() {
    // Create a callback to be called when the visualization API
    // has been loaded.
    Runnable onLoadCallback = new Runnable() {
        public void run() {
            // Create and populate a data table.
            DataTable data = DataTable.create();
            data.addColumn(DataTable.ColumnType.DATETIME, "time");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function A");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function B");

            DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");

            // create data 
            Date d = dtf.parse("2010-08-23");
            int n = 200; // number of datapoints
            for (int i = 0; i < n; i++) {
                data.addRow();
                data.setValue(i, 0, new Date(d.getTime()));
                data.setValue(i, 1, customFunctionA(i));
                data.setValue(i, 2, customFunctionB(i));
                d.setTime(d.getTime() + 1000 * 60); // steps of one minute
            }

            Graph.Options options = Graph.Options.create();
            options.setHeight("400px");
            options.setLineStyle(Graph.Options.LINESTYLE.DOT, 1);
            options.setLineColor("blue", 1);
            options.setLineLegend(false, 0);

            // create the graph, with data and options
            chart = new Graph(data, options);

            RootPanel.get("mygraph").add(chart);
        }
    };

    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback);
}

From source file:com.chap.links.client.GraphDemo2_interactive_and_custom_css.java

License:Apache License

/**
 * This is the entry point method./*w w w  .j av  a 2  s  .  c o m*/
 */
public void onModuleLoad() {
    // Create a callback to be called when the visualization API
    // has been loaded.
    Runnable onLoadCallback = new Runnable() {
        public void run() {
            RootPanel.get("txtStartDate").add(txtStartDate);
            RootPanel.get("txtEndDate").add(txtEndDate);
            RootPanel.get("btnSetRange").add(btnSetRange);

            // Add a handler to the add button
            btnSetRange.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    setRange();
                }
            });

            // Create and populate a data table.
            DataTable data = DataTable.create();
            data.addColumn(DataTable.ColumnType.DATETIME, "time");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function A");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function B");

            DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");

            // create data 
            Date d = dtf.parse("2010-08-23");
            int n = 10000; // number of datapoints
            for (int i = 0; i < n; i++) {
                data.addRow();
                data.setValue(i, 0, new Date(d.getTime()));
                data.setValue(i, 1, customFunction(i));
                data.setValue(i, 2, customFunction2(i));
                d.setTime(d.getTime() + 1000 * 60); // steps of one minute
            }

            Graph.Options options = Graph.Options.create();
            options.setHeight("400px");
            options.setVerticalStep(10);
            options.setLegendCheckboxes(true);
            //options.setScale(Graph.Options.SCALE.HOUR, 2);
            options.setLineColor("red", 1);
            options.setLineStyle(Graph.Options.LINESTYLE.DOT, 0);
            options.setLineRadius(1.0, 0);
            options.setLineColor("blue", 0);

            // create the linechart, with data and options
            graph = new Graph(data, options);

            // add event handlers
            graph.addRangeChangeHandler(createRangeChangeHandler(graph));

            RootPanel.get("mygraph").add(graph);

            getRange();
        }
    };

    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback);
}

From source file:com.chap.links.client.GraphEntryPoint.java

License:Apache License

/**
 * This is the entry point method.//from w  w w .  ja  va2s.c  o m
 */
public void onModuleLoad() {
    // Create a callback to be called when the visualization API
    // has been loaded.
    Runnable onLoadCallback = new Runnable() {
        public void run() {
            RootPanel.get("txtStartDate").add(txtStartDate);
            RootPanel.get("txtEndDate").add(txtEndDate);
            RootPanel.get("btnSetRange").add(btnSetRange);

            Button btnAutoRange = new Button("Auto Range");
            btnAutoRange.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    graph.setValueRangeAuto();
                    graph.setVisibleChartRangeAuto();
                }
            });
            RootPanel.get("btnAutoRange").add(btnAutoRange);

            // Add a handler to the add button
            btnSetRange.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    setRange();
                }
            });

            // Create and populate a data table.
            DataTable data = DataTable.create();
            data.addColumn(DataTable.ColumnType.DATETIME, "time");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function A");
            data.addColumn(DataTable.ColumnType.NUMBER, "Function B");

            DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");

            // create data 
            Date d = dtf.parse("2010-08-23");
            int n = 1000; // number of datapoints
            for (int i = 0; i < n; i++) {
                data.addRow();
                data.setValue(i, 0, new Date(d.getTime()));
                data.setValue(i, 1, customFunction(i) / 100);
                data.setValue(i, 2, customFunction2(i) / 100);
                d.setTime(d.getTime() + 1000 * 60); // steps of one minute
            }

            Graph.Options options = Graph.Options.create();
            options.setHeight("400px");
            options.setLegendCheckboxes(true);
            //options.setVerticalStep(10);
            //options.setScale(Graph.Options.SCALE.HOUR, 2);
            options.setLineStyle(Graph.Options.LINESTYLE.DOT, 0);
            options.setLineRadius(1.0, 0);
            options.setLineColor("#FFA500", 0);
            options.setLineVisibe(false, 1);
            options.setLineColor("#FF0000", 1);
            options.setLineStyle(Graph.Options.LINESTYLE.DOTLINE);
            options.setVerticalMin(-1);
            options.setVerticalMax(1);
            options.setMin(dtf.parse("2010-08-22"));
            options.setMax(dtf.parse("2010-08-24"));
            options.setZoomMin(1000L * 60L * 60L);

            /*
                    String json =       
                       "[{ " + 
                       "     \"label\" : \"Dataset A\", " + 
                       "     \"data\" : [" + 
                       "    {\"date\": 1281823200000, \"value\" : 12.5}," + 
                       "       {\"date\": 1281909600000, \"value\" : 3.5}" + 
                       "     ]" + 
                       "   }," + 
                       "   {" + 
                       "     \"label\" : \"Dataset B\"," +  
                       "     \"data\" : [" + 
                       "       {\"date\": 1281823200000, \"value\" : 3.2}," + 
                       "       {\"date\": 1281996000000, \"value\" : 6.1}" + 
                       "     ]" + 
                       "   }]";
                    JavaScriptObject jsonData = JsonUtils.safeEval(json);
                    */

            // create the linechart, with data and options
            graph = new Graph(data, options);

            //graph.draw(jso, options);

            // add event handlers
            graph.addRangeChangeHandler(createRangeChangeHandler(graph));

            RootPanel.get("mygraph").add(graph);

            getRange();

        }
    };

    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback);
}

From source file:com.google.gwt.visualization.sample.hellovisualization.client.VisualizationDemo.java

License:Apache License

/**
 * Creates a table and a view and shows both next to each other.
 *
 * @return a panel with two tables./*from   w  w  w .j a va2s .  c o m*/
 */
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;
}

From source file:com.google.gwt.visualization.sample.hellovisualization.client.VisualizationDemo.java

License:Apache License

/**
 * Creates a pie chart visualization.//from   w  w  w  .jav a2 s  .c  o  m
 *
 * @return panel with pie chart.
 */
private Widget createPieChart() {
    /* create a datatable */
    DataTable data = DataTable.create();
    data.addColumn(ColumnType.STRING, "Task");
    data.addColumn(ColumnType.NUMBER, "Hours per Day");
    data.addRows(5);
    data.setValue(0, 0, "Work");
    data.setValue(0, 1, 11);
    data.setValue(1, 0, "Eat");
    data.setValue(1, 1, 2);
    data.setValue(2, 0, "Commute");
    data.setValue(2, 1, 2);
    data.setValue(3, 0, "Watch TV");
    data.setValue(3, 1, 2);
    data.setValue(4, 0, "Sleep");
    data.setValue(4, 1, 7);

    /* create pie chart */

    PieOptions options = PieChart.createPieOptions();
    options.setWidth(400);
    options.setHeight(240);
    options.set3D(true);
    options.setTitle("My Daily Activities");
    return new PieChart(data, options);
}

From source file:com.google.gwt.visualization.sample.visualizationshowcase.client.AnnotatedDemo.java

License:Apache License

@SuppressWarnings("deprecation")
public AnnotatedDemo() {
    @SuppressWarnings("unused")
    int year, month, day;
    Options options = Options.create();//www  . j  a v a2 s . com
    options.setDisplayAnnotations(true);

    DataTable data = DataTable.create();
    data.addColumn(ColumnType.DATE, "Date");
    data.addColumn(ColumnType.NUMBER, "Sold Pencils");
    data.addColumn(ColumnType.STRING, "title1");
    data.addColumn(ColumnType.STRING, "text1");
    data.addColumn(ColumnType.NUMBER, "Sold Pens");
    data.addColumn(ColumnType.STRING, "title2");
    data.addColumn(ColumnType.STRING, "text2");
    data.addRows(6);
    try {
        data.setValue(0, 0, new Date(year = 2008 - 1900, month = 1, day = 1));
        data.setValue(1, 0, new Date(year = 2008 - 1900, month = 1, day = 2));
        data.setValue(2, 0, new Date(year = 2008 - 1900, month = 1, day = 3));
        data.setValue(3, 0, new Date(year = 2008 - 1900, month = 1, day = 4));
        data.setValue(4, 0, new Date(year = 2008 - 1900, month = 1, day = 5));
        data.setValue(5, 0, new Date(year = 2008 - 1900, month = 1, day = 6));
    } catch (JavaScriptException ex) {
        GWT.log("Error creating data table - Date bug on mac?", ex);
    }
    data.setValue(0, 1, 30000);
    data.setValue(0, 4, 40645);
    data.setValue(1, 1, 14045);
    data.setValue(1, 4, 20374);
    data.setValue(2, 1, 55022);
    data.setValue(2, 4, 50766);
    data.setValue(3, 1, 75284);
    data.setValue(3, 4, 14334);
    data.setValue(3, 5, "Out of Stock");
    data.setValue(3, 6, "Ran out of stock on pens at 4pm");
    data.setValue(4, 1, 41476);
    data.setValue(4, 2, "Bought 200k pens");
    data.setValue(4, 4, 66467);
    data.setValue(5, 1, 33322);
    data.setValue(5, 4, 39463);

    status.setText("'Ready' event was not yet fired");
    chart = new AnnotatedTimeLine(data, options, "700px", "240px");

    widget.add(chart);
    widget.add(status);
    widget.add(rangeStatus);

    addHandlers();
}

From source file:com.google.gwt.visualization.sample.visualizationshowcase.client.MapDemo.java

License:Apache License

public MapDemo() {
    Options options = Options.create();/*from w w w.j av a 2  s .c  o m*/
    options.setEnableScrollWheel(true);
    options.setLineColor("pink");
    options.setLineWidth(5);
    options.setMapType(MapVisualization.Type.HYBRID);
    options.setShowLine(true);
    options.setShowTip(true);

    DataTable data = DataTable.create();
    data.addColumn(ColumnType.NUMBER, "Lat");
    data.addColumn(ColumnType.NUMBER, "Lon");
    data.addColumn(ColumnType.STRING, "Name");
    data.addRows(4);
    data.setValue(0, 0, 37.4232);
    data.setValue(0, 1, -122.0853);
    data.setValue(0, 2, "Work");
    data.setValue(1, 0, 37.4289);
    data.setValue(1, 1, -122.1697);
    data.setValue(1, 2, "University");
    data.setValue(2, 0, 37.6153);
    data.setValue(2, 1, -122.3900);
    data.setValue(2, 2, "Airport");
    data.setValue(3, 0, 37.4422);
    data.setValue(3, 1, -122.1731);
    data.setValue(3, 2, "Shopping");

    widget = new MapVisualization(data, options, "400px", "300px");
}

From source file:com.google.gwt.visualization.sample.visualizationshowcase.client.MoneyDemo.java

License:Apache License

public MoneyDemo() {
    CommonChartOptions options = CommonChartOptions.create();

    options.setWidth(120);// w w  w.  ja va  2 s  .com
    options.setHeight(40);
    options.setTitle("Reveneues By Country");

    DataTable data = DataTable.create();

    data.addColumn(ColumnType.STRING, "Label");
    data.addColumn(ColumnType.NUMBER, "Value");
    data.addRows(4);
    data.setValue(0, 0, "France");
    data.setValue(1, 0, "Germany");
    data.setValue(2, 0, "USA");
    data.setValue(3, 0, "Poland");
    data.setCell(0, 1, 10, "$10,000", null);
    data.setCell(1, 1, 30, "$30,000", null);
    data.setCell(2, 1, 20, "$20,000", null);
    data.setCell(3, 1, 7.5, "$7,500", null);

    widget = new Visualization<AbstractDrawOptions>(data, options) {
        @Override
        protected native JavaScriptObject createJso(Element div) /*-{
                                                                 return new $wnd.PilesOfMoney(div);
                                                                 }-*/;
    };
}

From source file:com.google.gwt.visualization.sample.visualizationshowcase.client.MotionDemo.java

License:Apache License

@SuppressWarnings("deprecation")
public MotionDemo() {

    String protocol = Window.Location.getProtocol();
    if (protocol.startsWith("file")) {
        widget = new HTML("<font color=\"blue\"><i>Note: Protocol is: " + protocol
                + ".  Note that this visualization does not work when loading the HTML from "
                + "a local file. It works only when loading the HTML from a " + "web server. </i></font>");
        return;// w w  w  . j a  v  a2  s . com
    }

    @SuppressWarnings("unused")
    int year, month, day;

    Options options = Options.create();
    options.setHeight(300);
    options.setWidth(600);
    options.setState(STATE_STRING);
    DataTable data = DataTable.create();
    data.addRows(6);
    data.addColumn(ColumnType.STRING, "Fruit");
    data.addColumn(ColumnType.DATE, "Date");
    data.addColumn(ColumnType.NUMBER, "Sales");
    data.addColumn(ColumnType.NUMBER, "Expenses");
    data.addColumn(ColumnType.STRING, "Location");
    data.setValue(0, 0, "Apples");
    data.setValue(0, 2, 1000);
    data.setValue(0, 3, 300);
    data.setValue(0, 4, "East");
    data.setValue(1, 0, "Oranges");
    data.setValue(1, 2, 950);
    data.setValue(1, 3, 200);
    data.setValue(1, 4, "West");
    data.setValue(2, 0, "Bananas");
    data.setValue(2, 2, 300);
    data.setValue(2, 3, 250);
    data.setValue(2, 4, "West");
    data.setValue(3, 0, "Apples");
    data.setValue(3, 2, 1200);
    data.setValue(3, 3, 400);
    data.setValue(3, 4, "East");
    data.setValue(4, 0, "Oranges");
    data.setValue(4, 2, 900);
    data.setValue(4, 3, 150);
    data.setValue(4, 4, "West");
    data.setValue(5, 0, "Bananas");
    data.setValue(5, 2, 788);
    data.setValue(5, 3, 617);
    data.setValue(5, 4, "West");

    try {
        data.setValue(0, 1, new Date(year = 1988 - 1900, month = 0, day = 1));
        data.setValue(1, 1, new Date(year = 1988 - 1900, month = 0, day = 1));
        data.setValue(2, 1, new Date(year = 1988 - 1900, month = 0, day = 1));
        data.setValue(3, 1, new Date(year = 1988 - 1900, month = 1, day = 1));
        data.setValue(4, 1, new Date(year = 1988 - 1900, month = 1, day = 1));
        data.setValue(5, 1, new Date(year = 1988 - 1900, month = 1, day = 1));
    } catch (JavaScriptException ex) {
        GWT.log("Error creating data table - Date bug on mac?", ex);
    }

    final MotionChart motionChart = new MotionChart(data, options);
    motionChart.addStateChangeHandler(new StateChangeHandler() {

        @Override
        public void onStateChange(StateChangeEvent event) {
            String result = motionChart.getState();
            GWT.log(result);
        }
    });

    widget = motionChart;

}