Example usage for com.google.gwt.visualization.client.visualizations BarChart BarChart

List of usage examples for com.google.gwt.visualization.client.visualizations BarChart BarChart

Introduction

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

Prototype

public BarChart(AbstractDataTable data, Options options) 

Source Link

Usage

From source file:edu.cudenver.bios.glimmpse.client.panels.guided.EffectSizeBarChart.java

License:Open Source License

public EffectSizeBarChart() {
    VerticalPanel panel = new VerticalPanel();

    chart = new BarChart(createTable(), createOptions());
    chart.addSelectHandler(new SelectHandler() {
        public void onSelect(SelectEvent event) {
            // May be multiple selections.
            JsArray<Selection> selections = chart.getSelections();
            for (int i = 0; i < selections.length(); i++) {
                Selection selection = selections.get(i);
                if (selection.isCell()) {
                    // get cell row/column
                    selectedRow = selection.getRow();
                    selectedColumn = selection.getColumn();
                }/*from  w w  w  .  j  a va2  s .  c o m*/
            }

        }
    });
    panel.add(chart);

    Grid grid = new Grid(3, 4);

    final ListBox list1 = new ListBox();
    final ListBox list2 = new ListBox();
    final ListBox list3 = new ListBox();
    final ListBox list4 = new ListBox();
    for (int j = 0; j < 10; j++) {
        list1.addItem(Integer.toString(j));
        list2.addItem(Integer.toString(j));
        list3.addItem(Integer.toString(j));
        list4.addItem(Integer.toString(j));
    }
    list1.setSelectedIndex(1);
    list2.setSelectedIndex(2);
    list3.setSelectedIndex(2);
    list4.setSelectedIndex(1);
    grid.setWidget(0, 0, new HTML("male"));
    grid.setWidget(0, 1, new HTML("male"));
    grid.setWidget(0, 2, new HTML("female"));
    grid.setWidget(0, 3, new HTML("female"));
    grid.setWidget(1, 0, new HTML("A"));
    grid.setWidget(1, 1, new HTML("B"));
    grid.setWidget(1, 2, new HTML("A"));
    grid.setWidget(1, 3, new HTML("B"));
    grid.setWidget(2, 0, list1);
    grid.setWidget(2, 1, list2);
    grid.setWidget(2, 2, list3);
    grid.setWidget(2, 3, list4);
    panel.add(grid);
    list1.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent e) {
            ListBox lb = (ListBox) e.getSource();
            data.setValue(0, 1, Integer.parseInt(lb.getItemText(lb.getSelectedIndex())));
            chart.draw(data, options);
        }
    });
    list2.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent e) {
            ListBox lb = (ListBox) e.getSource();
            data.setValue(1, 1, Integer.parseInt(lb.getItemText(lb.getSelectedIndex())));
            chart.draw(data, options);
        }
    });
    list3.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent e) {
            ListBox lb = (ListBox) e.getSource();
            data.setValue(2, 1, Integer.parseInt(lb.getItemText(lb.getSelectedIndex())));
            chart.draw(data, options);
        }
    });
    list4.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent e) {
            ListBox lb = (ListBox) e.getSource();
            data.setValue(3, 1, Integer.parseInt(lb.getItemText(lb.getSelectedIndex())));
            chart.draw(data, options);
        }
    });

    ListBox common = new ListBox();
    common.addItem("Custom Relative Differences");
    common.addItem("Gender Main Effect");
    common.addItem("Treatment Main Effect");
    common.addItem("Gender by Treatment Interaction");
    common.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent e) {
            ListBox lb = (ListBox) e.getSource();
            String value = lb.getItemText(lb.getSelectedIndex());
            if (value.equals("Gender Main Effect")) {
                data.setValue(0, 1, 1);
                data.setValue(1, 1, 1);
                data.setValue(2, 1, 2);
                data.setValue(3, 1, 2);
                list1.setSelectedIndex(1);
                list2.setSelectedIndex(1);
                list3.setSelectedIndex(2);
                list4.setSelectedIndex(2);
                chart.draw(data, options);
            } else if (value.equals("Treatment Main Effect")) {
                data.setValue(0, 1, 2);
                data.setValue(1, 1, 1);
                data.setValue(2, 1, 2);
                data.setValue(3, 1, 1);
                list1.setSelectedIndex(2);
                list2.setSelectedIndex(1);
                list3.setSelectedIndex(2);
                list4.setSelectedIndex(1);
                chart.draw(data, options);
            } else {
                // interaction
                data.setValue(0, 1, 1);
                data.setValue(1, 1, 2);
                data.setValue(2, 1, 2);
                data.setValue(3, 1, 1);
                list1.setSelectedIndex(1);
                list2.setSelectedIndex(2);
                list3.setSelectedIndex(2);
                list4.setSelectedIndex(1);
                chart.draw(data, options);
            }
        }
    });
    panel.add(new HTML("Common patterns of differences:"));
    panel.add(common);
    initWidget(panel);
}