Search in sources :

Example 46 with DataSeriesItem

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

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

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

the class ScatterAndPolygon method fillScatter.

private void fillScatter(DataSeries series) {
    Random random = new Random(13);
    for (int i = 0; i < 100; i++) {
        double x = random.nextDouble() * 30 + 150;
        double y = 60;
        if (random.nextBoolean()) {
            y += random.nextDouble() * 15;
            if (random.nextBoolean() && x > 170) {
                y += random.nextDouble() * 30;
            }
        } else {
            y -= random.nextDouble() * 20;
        }
        series.add(new DataSeriesItem(x, y));
    }
}
Also used : Random(java.util.Random) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 49 with DataSeriesItem

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

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

the class ColumnWithNativeDrilldown method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");
    final Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market share, April, 2011");
    conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
    conf.getLegend().setEnabled(false);
    XAxis x = new XAxis();
    x.setType(AxisType.CATEGORY);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setTitle("Total percent market share");
    conf.addyAxis(y);
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new DataLabels(true));
    column.getDataLabels().setFormatter("this.y +'%'");
    conf.setPlotOptions(column);
    Tooltip tooltip = new Tooltip();
    tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
    conf.setTooltip(tooltip);
    DataSeries series = new DataSeries();
    series.setName("Browser brands");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);
    DataSeriesItem item = new DataSeriesItem("MSIE", 55.11);
    DataSeries drillSeries = new DataSeries("MSIE versions");
    drillSeries.setId("MSIE");
    String[] categories = new String[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" };
    Number[] ys = new Number[] { 10.85, 7.35, 33.06, 2.81 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Firefox", 21.63);
    drillSeries = new DataSeries("Firefox versions");
    drillSeries.setId("Firefox");
    categories = new String[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" };
    ys = new Number[] { 0.20, 0.83, 1.58, 13.12, 5.43 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Chrome", 11.94);
    drillSeries = new DataSeries("Chrome versions");
    drillSeries.setId("Chrome");
    categories = new String[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" };
    ys = new Number[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Safari", 7.15);
    drillSeries = new DataSeries("Safari versions");
    drillSeries.setId("Safari");
    categories = new String[] { "Safari 5.0", "Safari 4.0", "Safari Win 5.0", "Safari 4.1", "Safari/Maxthon", "Safari 3.1", "Safari 4.1" };
    ys = new Number[] { 4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Opera", 2.14);
    drillSeries = new DataSeries("Opera versions");
    drillSeries.setId("Opera");
    categories = new String[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" };
    ys = new Number[] { 0.12, 0.37, 1.65 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    conf.addSeries(series);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) 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)

Aggregations

DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)88 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 Chart (com.vaadin.addon.charts.Chart)57 Configuration (com.vaadin.addon.charts.model.Configuration)51 YAxis (com.vaadin.addon.charts.model.YAxis)27 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)19 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 XAxis (com.vaadin.addon.charts.model.XAxis)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 Random (java.util.Random)12 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)11 Test (org.junit.Test)11 Tooltip (com.vaadin.addon.charts.model.Tooltip)10 Marker (com.vaadin.addon.charts.model.Marker)9 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)8 PlotLine (com.vaadin.addon.charts.model.PlotLine)7 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)7 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)6 ListSeries (com.vaadin.addon.charts.model.ListSeries)6 Style (com.vaadin.addon.charts.model.style.Style)6