Search in sources :

Example 6 with PointClickListener

use of com.vaadin.addon.charts.PointClickListener 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)

Example 7 with PointClickListener

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

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

the class TreeMapPointClick method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.TREEMAP);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            lastAction.setValue(event.getClass().getSimpleName());
        }
    });
    chart.getConfiguration().addSeries(createSeries());
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.addComponent(chart);
    verticalLayout.addComponent(lastAction);
    return verticalLayout;
}
Also used : PointClickListener(com.vaadin.addon.charts.PointClickListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) Chart(com.vaadin.addon.charts.Chart)

Example 9 with PointClickListener

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

the class DateAxisAndClickEvent method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Date axis and click events");
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getxAxis().setType(AxisType.DATETIME);
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.HOUR_OF_DAY, 12);
    c.set(2013, 2, 11);
    DataSeries dataSeries = new DataSeries();
    Number[] values = new Number[] { 71.5, 29.9, 106.4 };
    Random r = new Random(0);
    for (Number number : values) {
        c.add(Calendar.MINUTE, r.nextInt(5));
        DataSeriesItem item = new DataSeriesItem(c.getTime(), number);
        dataSeries.add(item);
    }
    configuration.addSeries(dataSeries);
    chart.drawChart(configuration);
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            /*
                 * The axis value is in client side library's raw format: unix
                 * timestamp, "shifted" to UTC time zone
                 */
            ;
            double timeStampShiftedToUc = event.getxAxisValue();
            /*
                 * When working with Date objects, developers probably want to
                 * convert it to Date object at their local time zone.
                 */
            Notification.show("Clicked @ " + Util.toServerInstant(timeStampShiftedToUc));
        }
    });
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            /*
                 * Same with point clicks...
                 */
            ;
            double timeStampShiftedToUc = event.getX();
            Notification.show("Clicked Point with Date value " + Util.toServerInstant(timeStampShiftedToUc));
        }
    });
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Calendar(java.util.Calendar) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) Random(java.util.Random) PointClickListener(com.vaadin.addon.charts.PointClickListener) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

PointClickEvent (com.vaadin.addon.charts.PointClickEvent)9 PointClickListener (com.vaadin.addon.charts.PointClickListener)9 Chart (com.vaadin.addon.charts.Chart)8 DataSeries (com.vaadin.addon.charts.model.DataSeries)6 ChartClickEvent (com.vaadin.addon.charts.ChartClickEvent)5 ChartClickListener (com.vaadin.addon.charts.ChartClickListener)5 Configuration (com.vaadin.addon.charts.model.Configuration)5 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)5 VerticalLayout (com.vaadin.ui.VerticalLayout)4 DataLabels (com.vaadin.addon.charts.model.DataLabels)3 XAxis (com.vaadin.addon.charts.model.XAxis)3 YAxis (com.vaadin.addon.charts.model.YAxis)3 Legend (com.vaadin.addon.charts.model.Legend)2 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)2 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)2 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)2 ChartDrillupEvent (com.vaadin.addon.charts.ChartDrillupEvent)1 ChartDrillupListener (com.vaadin.addon.charts.ChartDrillupListener)1 CheckboxClickEvent (com.vaadin.addon.charts.CheckboxClickEvent)1 CheckboxClickListener (com.vaadin.addon.charts.CheckboxClickListener)1