Search in sources :

Example 1 with PlotOptionsScatter

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

the class WebXYChartSelection method createScatterChart.

private Chart createScatterChart() {
    final Chart scatterChart = new Chart(ChartType.SCATTER);
    scatterChart.setId("chart");
    scatterChart.getConfiguration().getChart().setZoomType(ZoomType.XY);
    scatterChart.getConfiguration().disableCredits();
    scatterChart.getConfiguration().setTitle("Selections as area ranges");
    scatterChart.getConfiguration().setSubTitle("Drag with mouse to make selections. Click the legend items to toggle visibility.");
    PlotOptionsScatter scatterOptions = new PlotOptionsScatter();
    scatterOptions.setAnimation(false);
    scatterOptions.setPointStart(1);
    DataSeries series = new DataSeries();
    series.setPlotOptions(scatterOptions);
    series.setName("Original");
    Random random = new Random(0);
    for (int i = 0; i < 20; i++) {
        DataSeriesItem dsi = new DataSeriesItem();
        dsi.setY(random.nextInt(10));
        dsi.setX(random.nextInt(10));
        series.add(dsi);
    }
    scatterChart.getConfiguration().addSeries(series);
    scatterChart.addChartSelectionListener(new ChartSelectionListener() {

        @Override
        public void onSelection(ChartSelectionEvent event) {
            double xStart = event.getSelectionStart();
            double xEnd = event.getSelectionEnd();
            double yStart = event.getValueStart();
            double yEnd = event.getValueEnd();
            Number[][] data = new Number[][] { { xStart, yStart, yEnd }, { xEnd, yStart, yEnd } };
            PlotOptionsArearange areaRangePlot = new PlotOptionsArearange();
            areaRangePlot.setFillOpacity(0.1f);
            areaRangePlot.setLineWidth(0);
            RangeSeries selectionSeries = new RangeSeries("Selection", data);
            selectionSeries.setPlotOptions(areaRangePlot);
            scatterChart.getConfiguration().addSeries(selectionSeries);
            scatterChart.drawChart();
            areaRangePlot.setAnimation(false);
        }
    });
    scatterChart.drawChart();
    return scatterChart;
}
Also used : PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) Random(java.util.Random) RangeSeries(com.vaadin.addon.charts.model.RangeSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) ChartSelectionEvent(com.vaadin.addon.charts.ChartSelectionEvent) ChartSelectionListener(com.vaadin.addon.charts.ChartSelectionListener) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) PlotOptionsArearange(com.vaadin.addon.charts.model.PlotOptionsArearange)

Example 2 with PlotOptionsScatter

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

the class ScatterWithRegressionLine method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    Color[] colors = getThemeColors();
    XAxis x = new XAxis();
    x.setMin(-0.5);
    x.setMax(5.5);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    conf.addyAxis(y);
    conf.setTitle("Scatter plot with regression line");
    DataSeries series = new DataSeries();
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setColor(colors[1]);
    series.setPlotOptions(plotOptions);
    series.setName("Regression Line");
    List<DataSeriesItem> list = new ArrayList<DataSeriesItem>();
    list.add(new DataSeriesItem(0, 1.11));
    list.add(new DataSeriesItem(5, 4.51));
    series.setData(list);
    plotOptions.setMarker(new Marker(true));
    plotOptions.setEnableMouseTracking(true);
    Hover hover = new Hover();
    hover.setLineWidth(0);
    States states = new States();
    states.setHover(hover);
    plotOptions.setStates(states);
    conf.addSeries(series);
    ListSeries listSeries = new ListSeries("Observations", 1, 1.5, 2.8, 3.5, 3.9, 4.2);
    PlotOptionsScatter plotOptions2 = new PlotOptionsScatter();
    listSeries.setPlotOptions(plotOptions2);
    Marker marker = new Marker(true);
    marker.setRadius(4);
    plotOptions2.setMarker(marker);
    conf.addSeries(listSeries);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) Color(com.vaadin.addon.charts.model.style.Color) ArrayList(java.util.ArrayList) Marker(com.vaadin.addon.charts.model.Marker) XAxis(com.vaadin.addon.charts.model.XAxis) States(com.vaadin.addon.charts.model.States) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with PlotOptionsScatter

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

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

the class Basic3DScatter method createScatterChart.

private Chart createScatterChart() {
    final Chart scatterChart = new Chart(ChartType.SCATTER);
    scatterChart.setId("chart");
    scatterChart.getConfiguration().disableCredits();
    scatterChart.getConfiguration().setTitle("Points of a sphere");
    PlotOptionsScatter scatterOptions = new PlotOptionsScatter();
    scatterOptions.setAnimation(false);
    scatterOptions.setPointStart(1);
    DataSeries higherX = new DataSeries();
    higherX.setName("Higher X");
    DataSeries higherY = new DataSeries();
    higherY.setName("Higher Y");
    DataSeries higherZ = new DataSeries();
    higherZ.setName("Higher Z");
    fillSeries(higherX, higherY, higherZ);
    scatterChart.getConfiguration().addSeries(higherX);
    scatterChart.getConfiguration().addSeries(higherY);
    scatterChart.getConfiguration().addSeries(higherZ);
    XAxis x = scatterChart.getConfiguration().getxAxis();
    x.setGridLineWidth(1);
    x.setExtremes(-3, 3);
    if (getCurrentTheme().getxAxis().getGridLineColor() != null) {
        x.setGridLineColor(getCurrentTheme().getxAxis().getGridLineColor());
    }
    YAxis y = scatterChart.getConfiguration().getyAxis();
    y.setExtremes(-1, 1);
    ZAxis z = scatterChart.getConfiguration().getzAxis();
    z.setMin(-1);
    z.setMax(1);
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(10);
    options3d.setBeta(30);
    options3d.setDepth(80);
    options3d.setViewDistance(40);
    Frame frame = new Frame();
    Bottom bottom = new Bottom();
    bottom.setSize(1);
    frame.setBottom(bottom);
    options3d.setFrame(frame);
    scatterChart.getConfiguration().getChart().setOptions3d(options3d);
    scatterChart.drawChart();
    return scatterChart;
}
Also used : Frame(com.vaadin.addon.charts.model.Frame) PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) ZAxis(com.vaadin.addon.charts.model.ZAxis) Bottom(com.vaadin.addon.charts.model.Bottom) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) Options3d(com.vaadin.addon.charts.model.Options3d) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 5 with PlotOptionsScatter

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

the class ThreeDAxisConfiguration method createScatterChart.

private Chart createScatterChart() {
    final Chart scatterChart = new Chart(ChartType.SCATTER);
    scatterChart.setWidth("450px");
    scatterChart.setId("chart");
    scatterChart.getConfiguration().disableCredits();
    scatterChart.getConfiguration().setTitle("Points of a sphere");
    PlotOptionsScatter scatterOptions = new PlotOptionsScatter();
    scatterOptions.setAnimation(false);
    scatterOptions.setPointStart(1);
    DataSeries higherX = new DataSeries();
    higherX.setName("Higher X");
    DataSeries higherY = new DataSeries();
    higherY.setName("Higher Y");
    DataSeries higherZ = new DataSeries();
    higherZ.setName("Higher Z");
    fillSeries(higherX, higherY, higherZ);
    scatterChart.getConfiguration().addSeries(higherX);
    scatterChart.getConfiguration().addSeries(higherY);
    scatterChart.getConfiguration().addSeries(higherZ);
    XAxis x = scatterChart.getConfiguration().getxAxis();
    x.setGridLineWidth(1);
    x.setExtremes(-3, 3);
    if (getCurrentTheme().getxAxis().getGridLineColor() != null) {
        x.setGridLineColor(getCurrentTheme().getxAxis().getGridLineColor());
    }
    setAxisConfiguration(scatterChart.getConfiguration().getxAxis());
    setAxisConfiguration(scatterChart.getConfiguration().getyAxis());
    setAxisConfiguration(scatterChart.getConfiguration().getzAxis());
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(10);
    options3d.setBeta(60);
    options3d.setDepth(200);
    options3d.setViewDistance(40);
    Frame frame = new Frame();
    Bottom bottom = new Bottom();
    bottom.setSize(1);
    frame.setBottom(bottom);
    options3d.setFrame(frame);
    scatterChart.getConfiguration().getChart().setOptions3d(options3d);
    scatterChart.drawChart();
    return scatterChart;
}
Also used : Frame(com.vaadin.addon.charts.model.Frame) PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) Bottom(com.vaadin.addon.charts.model.Bottom) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) Options3d(com.vaadin.addon.charts.model.Options3d)

Aggregations

Chart (com.vaadin.addon.charts.Chart)7 DataSeries (com.vaadin.addon.charts.model.DataSeries)7 PlotOptionsScatter (com.vaadin.addon.charts.model.PlotOptionsScatter)7 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)5 XAxis (com.vaadin.addon.charts.model.XAxis)5 Configuration (com.vaadin.addon.charts.model.Configuration)4 YAxis (com.vaadin.addon.charts.model.YAxis)4 Bottom (com.vaadin.addon.charts.model.Bottom)2 Frame (com.vaadin.addon.charts.model.Frame)2 Marker (com.vaadin.addon.charts.model.Marker)2 Options3d (com.vaadin.addon.charts.model.Options3d)2 PlotOptionsPolygon (com.vaadin.addon.charts.model.PlotOptionsPolygon)2 ChartSelectionEvent (com.vaadin.addon.charts.ChartSelectionEvent)1 ChartSelectionListener (com.vaadin.addon.charts.ChartSelectionListener)1 Hover (com.vaadin.addon.charts.model.Hover)1 ListSeries (com.vaadin.addon.charts.model.ListSeries)1 PlotOptionsArearange (com.vaadin.addon.charts.model.PlotOptionsArearange)1 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)1 RangeSeries (com.vaadin.addon.charts.model.RangeSeries)1 States (com.vaadin.addon.charts.model.States)1