Search in sources :

Example 1 with LegendItemClickListener

use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.

the class ServerSideEvents method addEventListeners.

private Layout addEventListeners() {
    eventListeners = new VerticalLayout();
    eventListeners.setCaption("Event listeners:");
    final ChartClickListener listener = new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Chart click", "ChartClick", new ListenerToggle() {

        @Override
        public void add() {
            chart.addChartClickListener(listener);
        }

        @Override
        public void remove() {
            chart.removeChartClickListener(listener);
        }
    });
    final PointClickListener pcListener = new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Point click", "PointClick", new ListenerToggle() {

        @Override
        public void add() {
            chart.addPointClickListener(pcListener);
        }

        @Override
        public void remove() {
            chart.removePointClickListener(pcListener);
        }
    });
    final CheckboxClickListener cbListener = new CheckboxClickListener() {

        @Override
        public void onClick(CheckboxClickEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Checkbox click", "CheckboxClick", new ListenerToggle() {

        @Override
        public void add() {
            chart.addCheckBoxClickListener(cbListener);
        }

        @Override
        public void remove() {
            chart.removeCheckBoxClickListener(cbListener);
        }
    });
    final LegendItemClickListener legendItemListener = new LegendItemClickListener() {

        @Override
        public void onClick(LegendItemClickEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Legend item click", "LegendItemClick", new ListenerToggle() {

        @Override
        public void add() {
            chart.addLegendItemClickListener(legendItemListener);
            visibilityToggling.setValue(true);
        }

        @Override
        public void remove() {
            chart.removeLegendItemClickListener(legendItemListener);
        }
    });
    final SeriesHideListener hideListener = new SeriesHideListener() {

        @Override
        public void onHide(SeriesHideEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Series hide", "SeriesHide", new ListenerToggle() {

        @Override
        public void add() {
            chart.addSeriesHideListener(hideListener);
        }

        @Override
        public void remove() {
            chart.removeSeriesHideListener(hideListener);
        }
    });
    final SeriesShowListener show = new SeriesShowListener() {

        @Override
        public void onShow(SeriesShowEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Series show", "SeriesShow", new ListenerToggle() {

        @Override
        public void add() {
            chart.addSeriesShowListener(show);
        }

        @Override
        public void remove() {
            chart.removeSeriesShowListener(show);
        }
    });
    final XAxesExtremesChangeListener xaxesListener = new XAxesExtremesChangeListener() {

        @Override
        public void onXAxesExtremesChange(XAxesExtremesChangeEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("XAxes extremes change", "XAxesExtremes", new ListenerToggle() {

        @Override
        public void add() {
            chart.addXAxesExtremesChangeListener(xaxesListener);
        }

        @Override
        public void remove() {
            chart.removeXAxesExtremesChangeListener(xaxesListener);
        }
    });
    final YAxesExtremesChangeListener yaxesListener = new YAxesExtremesChangeListener() {

        @Override
        public void onYAxesExtremesChange(YAxesExtremesChangeEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Y axes extremes change", "YAxesExtremes", new ListenerToggle() {

        @Override
        public void add() {
            chart.addYAxesExtremesChangeListener(yaxesListener);
        }

        @Override
        public void remove() {
            chart.removeYAxesExtremesChangeListener(yaxesListener);
        }
    });
    final PointSelectListener selectListener = new PointSelectListener() {

        @Override
        public void onSelect(PointSelectEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Point select", "PointSelect", new ListenerToggle() {

        @Override
        public void add() {
            chart.addPointSelectListener(selectListener);
        }

        @Override
        public void remove() {
            chart.removePointSelectListener(selectListener);
        }
    });
    final PointUnselectListener unselectListener = new PointUnselectListener() {

        @Override
        public void onUnselect(PointUnselectEvent event) {
            logEvent(event);
        }
    };
    addToggleForListener("Point unselect", "PointUnselect", new ListenerToggle() {

        @Override
        public void add() {
            chart.addPointUnselectListener(unselectListener);
        }

        @Override
        public void remove() {
            chart.removePointUnselectListener(unselectListener);
        }
    });
    return eventListeners;
}
Also used : LegendItemClickListener(com.vaadin.addon.charts.LegendItemClickListener) PointSelectEvent(com.vaadin.addon.charts.PointSelectEvent) PointUnselectListener(com.vaadin.addon.charts.PointUnselectListener) SeriesShowEvent(com.vaadin.addon.charts.SeriesShowEvent) CheckboxClickListener(com.vaadin.addon.charts.CheckboxClickListener) SeriesHideListener(com.vaadin.addon.charts.SeriesHideListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) SeriesShowListener(com.vaadin.addon.charts.SeriesShowListener) PointSelectListener(com.vaadin.addon.charts.PointSelectListener) PointUnselectEvent(com.vaadin.addon.charts.PointUnselectEvent) XAxesExtremesChangeListener(com.vaadin.addon.charts.XAxesExtremesChangeListener) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) YAxesExtremesChangeEvent(com.vaadin.addon.charts.YAxesExtremesChangeEvent) XAxesExtremesChangeEvent(com.vaadin.addon.charts.XAxesExtremesChangeEvent) LegendItemClickEvent(com.vaadin.addon.charts.LegendItemClickEvent) CheckboxClickEvent(com.vaadin.addon.charts.CheckboxClickEvent) PointClickListener(com.vaadin.addon.charts.PointClickListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SeriesHideEvent(com.vaadin.addon.charts.SeriesHideEvent) YAxesExtremesChangeListener(com.vaadin.addon.charts.YAxesExtremesChangeListener)

Example 2 with LegendItemClickListener

use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.

the class ToggledSeriesVisibility method getChart.

@Override
protected Component getChart() {
    chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Monthly Average Rainfall");
    conf.setSubTitle("Source: WorldClimate.com");
    XAxis x = new XAxis();
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    conf.addyAxis(y);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(100);
    legend.setY(70);
    legend.setFloating(true);
    legend.setShadow(true);
    conf.setLegend(legend);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.x +': '+ this.y +' mm'");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plot = new PlotOptionsColumn();
    plot.setPointPadding(0.2);
    plot.setBorderWidth(0);
    conf.addSeries(tokyo);
    conf.addSeries(newYork);
    conf.addSeries(berlin);
    conf.addSeries(london);
    chart.addLegendItemClickListener(new LegendItemClickListener() {

        @Override
        public void onClick(LegendItemClickEvent event) {
            /*
                 * Visibility of the series is also toggled from legend clicks
                 * by default. Still developers might wish to override this
                 * behavior if the visibility is also controlled by other
                 * components like here or if e.g. multiple charts are bound
                 * together (hiding series in one chart should hide related data
                 * in other chart as well).
                 */
            ListSeries series = (ListSeries) event.getSeries();
            /*
                 * Toggle checked in option group. As a side effect (via value
                 * change listener, see setup method) the visibility will change
                 * in the chart as well.
                 */
            if (series.isVisible()) {
                checkBoxGroup.deselect(series);
            } else {
                checkBoxGroup.select(series);
            }
        }
    });
    chart.drawChart(conf);
    return chart;
}
Also used : LegendItemClickListener(com.vaadin.addon.charts.LegendItemClickListener) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) LegendItemClickEvent(com.vaadin.addon.charts.LegendItemClickEvent) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with LegendItemClickListener

use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.

the class PieWithLegend method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares at a specific website, 2010");
    Tooltip tooltip = new Tooltip();
    tooltip.setValueDecimals(1);
    tooltip.setPointFormat("{series.name}: <b>{point.percentage}%</b>");
    conf.setTooltip(tooltip);
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setAllowPointSelect(true);
    plotOptions.setCursor(Cursor.POINTER);
    plotOptions.setShowInLegend(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    series.add(new DataSeriesItem("Firefox", 45.0));
    series.add(new DataSeriesItem("IE", 26.8));
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Safari", 8.5));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("Others", 0.7));
    conf.setSeries(series);
    chart.addLegendItemClickListener(new LegendItemClickListener() {

        @Override
        public void onClick(LegendItemClickEvent event) {
            Notification.show("Legend item click" + " : " + event.getSeriesItemIndex() + " : " + ((DataSeries) event.getSeries()).get(event.getSeriesItemIndex()).getName());
        }
    });
    chart.drawChart(conf);
    return chart;
}
Also used : LegendItemClickListener(com.vaadin.addon.charts.LegendItemClickListener) PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) Configuration(com.vaadin.addon.charts.model.Configuration) LegendItemClickEvent(com.vaadin.addon.charts.LegendItemClickEvent) Tooltip(com.vaadin.addon.charts.model.Tooltip) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

LegendItemClickEvent (com.vaadin.addon.charts.LegendItemClickEvent)3 LegendItemClickListener (com.vaadin.addon.charts.LegendItemClickListener)3 Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 Tooltip (com.vaadin.addon.charts.model.Tooltip)2 ChartClickEvent (com.vaadin.addon.charts.ChartClickEvent)1 ChartClickListener (com.vaadin.addon.charts.ChartClickListener)1 CheckboxClickEvent (com.vaadin.addon.charts.CheckboxClickEvent)1 CheckboxClickListener (com.vaadin.addon.charts.CheckboxClickListener)1 PointClickEvent (com.vaadin.addon.charts.PointClickEvent)1 PointClickListener (com.vaadin.addon.charts.PointClickListener)1 PointSelectEvent (com.vaadin.addon.charts.PointSelectEvent)1 PointSelectListener (com.vaadin.addon.charts.PointSelectListener)1 PointUnselectEvent (com.vaadin.addon.charts.PointUnselectEvent)1 PointUnselectListener (com.vaadin.addon.charts.PointUnselectListener)1 SeriesHideEvent (com.vaadin.addon.charts.SeriesHideEvent)1 SeriesHideListener (com.vaadin.addon.charts.SeriesHideListener)1 SeriesShowEvent (com.vaadin.addon.charts.SeriesShowEvent)1 SeriesShowListener (com.vaadin.addon.charts.SeriesShowListener)1 XAxesExtremesChangeEvent (com.vaadin.addon.charts.XAxesExtremesChangeEvent)1