Search in sources :

Example 1 with ChartClickListener

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

the class AbstractPointClickCoordinatesChart method createChart.

protected Chart createChart() {
    Chart chart = new Chart(type);
    chart.setWidth("900px");
    chart.setHeight("450px");
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            lastAction.setValue("PointClickEvent: absoluteX: " + event.getAbsoluteX() + " - absoluteY: " + event.getAbsoluteY());
        }
    });
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            lastAction.setValue("ChartClickEvent: absoluteX: " + event.getAbsoluteX() + " - absoluteY: " + event.getAbsoluteY());
        }
    });
    addSeries(chart.getConfiguration());
    return chart;
}
Also used : ChartClickListener(com.vaadin.addon.charts.ChartClickListener) PointClickListener(com.vaadin.addon.charts.PointClickListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) Chart(com.vaadin.addon.charts.Chart) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent)

Example 2 with ChartClickListener

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

the class Events method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    final Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Click to add point");
    configuration.getChart().setType(ChartType.SPLINE);
    final ListSeries series = new ListSeries(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    configuration.setSeries(series);
    chart.drawChart(configuration);
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            double getyAxisValue = event.getyAxisValue();
            series.addData(getyAxisValue);
        }
    });
    return chart;
}
Also used : ChartClickListener(com.vaadin.addon.charts.ChartClickListener) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Chart(com.vaadin.addon.charts.Chart) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent)

Example 3 with ChartClickListener

use of com.vaadin.addon.charts.ChartClickListener 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 4 with ChartClickListener

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

the class BasicLineGettingMousePointerPosition method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setId("chart");
    Color[] colors = getThemeColors();
    Configuration conf = chart.getConfiguration();
    conf.getChart().setZoomType(ZoomType.XY);
    conf.setTitle("Average Monthly Temperature and Rainfall in Tokyo");
    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 primary = new YAxis();
    primary.setTitle("Temperature");
    Style style = new Style();
    style.setColor(colors[0]);
    primary.getTitle().setStyle(style);
    conf.addyAxis(primary);
    YAxis snd = new YAxis();
    snd.setTitle("Rainfall");
    snd.setOpposite(true);
    style = new Style();
    style.setColor(colors[1]);
    snd.getTitle().setStyle(style);
    conf.addyAxis(snd);
    Tooltip tooltip = new Tooltip(false);
    conf.setTooltip(tooltip);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setX(120);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    conf.setLegend(legend);
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsColumn());
    series.setName("Rainfall");
    series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    series.setyAxis(1);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    series.setPlotOptions(plotOptions);
    series.setName("Temperature");
    series.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    conf.addSeries(series);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            Window win = new Window("PointClickEvent window");
            win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
            win.setPositionX(event.getAbsoluteX());
            win.setPositionY(event.getAbsoluteY());
            getUI().addWindow(win);
        }
    });
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            Window win = new Window("Chart Click Event Window");
            win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
            win.setPositionX(event.getAbsoluteX());
            win.setPositionY(event.getAbsoluteY());
            getUI().addWindow(win);
        }
    });
    return chart;
}
Also used : Window(com.vaadin.ui.Window) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) Tooltip(com.vaadin.addon.charts.model.Tooltip) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) Label(com.vaadin.ui.Label) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) PointClickListener(com.vaadin.addon.charts.PointClickListener) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 5 with ChartClickListener

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

the class ClickToAddPoint method getChart.

@Override
protected Component getChart() {
    lastAction.setId("lastAction");
    eventDetails.setId("eventDetails");
    chart = new Chart();
    chart.setId("chart");
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SCATTER);
    configuration.getTitle().setText("User supplied data");
    configuration.getSubTitle().setText("Click the plot area to add a point. Click a point to remove it.");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setMinPadding(0.2);
    xAxis.setMaxPadding(0.2);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
    yAxis.setMinPadding(0.2);
    yAxis.setMaxPadding(0.2);
    Legend legend = configuration.getLegend();
    legend.setEnabled(false);
    configuration.setExporting(false);
    PlotOptionsSeries opt = new PlotOptionsSeries();
    opt.setLineWidth(1);
    configuration.setPlotOptions(opt);
    final DataSeries series = new DataSeries();
    series.add(new DataSeriesItem(20, 20));
    series.add(new DataSeriesItem(80, 80));
    configuration.setSeries(series);
    chart.drawChart(configuration);
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            double x = Math.round(event.getxAxisValue());
            double y = Math.round(event.getyAxisValue());
            series.add(new DataSeriesItem(x, y));
            lastAction.setValue("Added point " + x + "," + y);
            eventDetails.setValue(createEventString(event));
        }
    });
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            DataSeries ds = (DataSeries) event.getSeries();
            DataSeriesItem dataSeriesItem2 = ds.get(event.getPointIndex());
            ds.remove(dataSeriesItem2);
            lastAction.setValue("Removed point at index " + event.getPointIndex());
            eventDetails.setValue(createEventString(event));
        }
    });
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    verticalLayout.addComponent(chart);
    verticalLayout.addComponent(lastAction);
    verticalLayout.addComponent(eventDetails);
    return verticalLayout;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) XAxis(com.vaadin.addon.charts.model.XAxis) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) PointClickListener(com.vaadin.addon.charts.PointClickListener) VerticalLayout(com.vaadin.ui.VerticalLayout) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

ChartClickEvent (com.vaadin.addon.charts.ChartClickEvent)6 ChartClickListener (com.vaadin.addon.charts.ChartClickListener)6 Chart (com.vaadin.addon.charts.Chart)5 PointClickEvent (com.vaadin.addon.charts.PointClickEvent)5 PointClickListener (com.vaadin.addon.charts.PointClickListener)5 Configuration (com.vaadin.addon.charts.model.Configuration)4 DataSeries (com.vaadin.addon.charts.model.DataSeries)3 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)2 Legend (com.vaadin.addon.charts.model.Legend)2 XAxis (com.vaadin.addon.charts.model.XAxis)2 YAxis (com.vaadin.addon.charts.model.YAxis)2 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 CheckboxClickEvent (com.vaadin.addon.charts.CheckboxClickEvent)1 CheckboxClickListener (com.vaadin.addon.charts.CheckboxClickListener)1 LegendItemClickEvent (com.vaadin.addon.charts.LegendItemClickEvent)1 LegendItemClickListener (com.vaadin.addon.charts.LegendItemClickListener)1 PointSelectEvent (com.vaadin.addon.charts.PointSelectEvent)1 PointSelectListener (com.vaadin.addon.charts.PointSelectListener)1 PointUnselectEvent (com.vaadin.addon.charts.PointUnselectEvent)1