Search in sources :

Example 56 with DataSeries

use of com.vaadin.addon.charts.model.DataSeries 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 57 with DataSeries

use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.

the class ColumnLineAndPie method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Combined Chart");
    conf.setExporting(true);
    conf.getExporting().setWidth(800);
    XAxis x = new XAxis();
    x.setCategories(new String[] { "Apples", "Oranges", "Pears", "Bananas", "Plums" });
    conf.addxAxis(x);
    Style labelStyle = new Style();
    labelStyle.setTop("8px");
    labelStyle.setLeft("40px");
    conf.setLabels(new HTMLLabels(labelStyle, new HTMLLabelItem("Total fruit consumption")));
    DataSeries series = new DataSeries();
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Jane");
    series.setData(3, 2, 1, 3, 4);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("John");
    series.setData(2, 3, 5, 7, 6);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Joe");
    series.setData(4, 3, 3, 9, 0);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline splinePlotOptions = new PlotOptionsSpline();
    Marker marker = new Marker();
    marker.setLineWidth(2);
    marker.setLineColor(new SolidColor("black"));
    marker.setFillColor(new SolidColor("white"));
    splinePlotOptions.setMarker(marker);
    splinePlotOptions.setColor(new SolidColor("black"));
    series.setPlotOptions(splinePlotOptions);
    series.setName("Average");
    series.setData(3, 2.67, 3, 6.33, 3.33);
    conf.addSeries(series);
    series = new DataSeries();
    series.setPlotOptions(new PlotOptionsPie());
    series.setName("Total consumption");
    DataSeriesItem item = new DataSeriesItem("Jane", 13);
    series.add(item);
    item = new DataSeriesItem("John", 23);
    series.add(item);
    item = new DataSeriesItem("Joe", 19);
    series.add(item);
    PlotOptionsPie plotOptionsPie = new PlotOptionsPie();
    plotOptionsPie.setSize("100px");
    plotOptionsPie.setCenter("100px", "80px");
    plotOptionsPie.setShowInLegend(false);
    plotOptionsPie.setShowInLegend(false);
    series.setPlotOptions(plotOptionsPie);
    conf.addSeries(series);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) HTMLLabels(com.vaadin.addon.charts.model.HTMLLabels) HTMLLabelItem(com.vaadin.addon.charts.model.HTMLLabelItem) PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 58 with DataSeries

use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.

the class ScatterAndPolygon method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart(ChartType.SCATTER);
    Configuration conf = chart.getConfiguration();
    chart.setId("chart");
    conf.getChart().setZoomType(ZoomType.XY);
    conf.disableCredits();
    conf.setTitle("Height vs Weight");
    conf.setSubTitle("Polygon series in Vaadin Charts.");
    Tooltip tooltip = conf.getTooltip();
    tooltip.setHeaderFormat("<b>{series.name}</b><br>");
    tooltip.setPointFormat("{point.x} cm, {point.y} kg");
    XAxis xAxis = conf.getxAxis();
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    xAxis.setTitle("Height (cm)");
    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Weight (kg)");
    PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
    DataSeries scatter = new DataSeries();
    scatter.setPlotOptions(plotOptionsScatter);
    scatter.setName("Observations");
    fillScatter(scatter);
    DataSeries polygon = new DataSeries();
    PlotOptionsPolygon plotOptionsPolygon = new PlotOptionsPolygon();
    plotOptionsPolygon.setEnableMouseTracking(false);
    polygon.setPlotOptions(plotOptionsPolygon);
    polygon.setName("Target");
    polygon.add(new DataSeriesItem(153, 42));
    polygon.add(new DataSeriesItem(149, 46));
    polygon.add(new DataSeriesItem(149, 55));
    polygon.add(new DataSeriesItem(152, 60));
    polygon.add(new DataSeriesItem(159, 70));
    polygon.add(new DataSeriesItem(170, 77));
    polygon.add(new DataSeriesItem(180, 70));
    polygon.add(new DataSeriesItem(180, 60));
    polygon.add(new DataSeriesItem(173, 52));
    polygon.add(new DataSeriesItem(166, 45));
    conf.addSeries(polygon);
    conf.addSeries(scatter);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) PlotOptionsPolygon(com.vaadin.addon.charts.model.PlotOptionsPolygon) Tooltip(com.vaadin.addon.charts.model.Tooltip) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 59 with DataSeries

use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.

the class BasicColumnWithPointWidthAndRange method getChart.

@Override
protected Component getChart() {
    chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Visualize point width and point range");
    plotOptions = new PlotOptionsColumn();
    // plotOptions.setPointRange(10);
    plotOptions.setPointWidth(100);
    conf.setPlotOptions(plotOptions);
    DataSeries dataSeries = new DataSeries();
    dataSeries.addData(new Number[][] { { 0, 1 }, { 2, 2 }, { 10, 3 } });
    conf.setSeries(dataSeries);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart)

Example 60 with DataSeries

use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.

the class ColumnWithLazyMultiLevelDrilldown method getPointDrilldown.

private Series getPointDrilldown(DataSeriesItem point) {
    String pointId = point.getId();
    DataSeries series = drillSeries.get(pointId);
    return series;
}
Also used : DataSeries(com.vaadin.addon.charts.model.DataSeries)

Aggregations

DataSeries (com.vaadin.addon.charts.model.DataSeries)118 Chart (com.vaadin.addon.charts.Chart)81 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)81 Configuration (com.vaadin.addon.charts.model.Configuration)71 YAxis (com.vaadin.addon.charts.model.YAxis)38 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)26 XAxis (com.vaadin.addon.charts.model.XAxis)25 DataLabels (com.vaadin.addon.charts.model.DataLabels)21 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)17 Tooltip (com.vaadin.addon.charts.model.Tooltip)15 Test (org.junit.Test)15 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)14 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)14 Marker (com.vaadin.addon.charts.model.Marker)13 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)13 Style (com.vaadin.addon.charts.model.style.Style)10 Random (java.util.Random)10 Legend (com.vaadin.addon.charts.model.Legend)9 PlotLine (com.vaadin.addon.charts.model.PlotLine)9 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)8