Search in sources :

Example 1 with PlotOptionsSeries

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

the class CompareMultipleSeries method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("(this.value > 0 ? ' + ' : '') + this.value + '%'");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span style=\"color:{series.color}\">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>");
    tooltip.setValueDecimals(2);
    configuration.setTooltip(tooltip);
    DataSeries aaplSeries = new DataSeries();
    aaplSeries.setName("AAPL");
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    DataSeries googSeries = new DataSeries();
    googSeries.setName("GOOG");
    for (StockPrices.PriceData data : StockPrices.fetchGoogPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        googSeries.add(item);
    }
    DataSeries msftSeries = new DataSeries();
    msftSeries.setName("MSFT");
    for (StockPrices.PriceData data : StockPrices.fetchMsftPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        msftSeries.add(item);
    }
    configuration.setSeries(aaplSeries, googSeries, msftSeries);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setCompare(PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) Tooltip(com.vaadin.addon.charts.model.Tooltip) Labels(com.vaadin.addon.charts.model.Labels) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with PlotOptionsSeries

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

the class DataProviderSeriesBeanSerializer method serialize.

@Override
public void serialize(DataProviderSeries bean, BeanSerializerDelegator<DataProviderSeries> serializer, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();
    if (bean.getPlotOptions() != null && !(bean.getPlotOptions() instanceof PlotOptionsSeries)) {
        jgen.writeObjectField("type", bean.getPlotOptions().getChartType());
    }
    // write other fields as per normal serialization rules
    serializer.serializeFields(bean, jgen, provider);
    ArrayNode data = createDataArray(bean);
    jgen.writeObjectField("data", data);
    jgen.writeEndObject();
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries)

Example 3 with PlotOptionsSeries

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

the class TimeSeriesIntervalUnit method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("Point interval test");
    configuration.getxAxis().setType(AxisType.DATETIME);
    final PlotOptionsSeries plotOptions = new PlotOptionsSeries();
    try {
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        plotOptions.setPointStart(df.parse("20150101"));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    plotOptions.setPointInterval(1);
    plotOptions.setPointIntervalUnit(IntervalUnit.MONTH);
    configuration.setPlotOptions(plotOptions);
    ListSeries ls = new ListSeries();
    ls.setData(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(ls);
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(false);
    layout.setMargin(false);
    layout.addComponent(chart);
    layout.addComponent(new Button("one day interval", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            plotOptions.setPointInterval(24 * 3600 * 1000);
            plotOptions.setPointIntervalUnit(null);
            chart.drawChart();
        }
    }));
    return layout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries)

Example 4 with PlotOptionsSeries

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

the class DataSeriesItemJSONSerializationTest method toJSON_PlotOptionsSeriesIsSet_SeriesSerializedWithoutType.

@Test
public void toJSON_PlotOptionsSeriesIsSet_SeriesSerializedWithoutType() {
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSeries());
    String expected = "{\"data\":[]}";
    assertEquals(expected, toJSON(series));
}
Also used : DataSeries(com.vaadin.addon.charts.model.DataSeries) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) Test(org.junit.Test)

Example 5 with PlotOptionsSeries

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

the class StackedBar method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.BAR);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Stacked bar chart");
    XAxis x = new XAxis();
    x.setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Total fruit consumption");
    conf.addyAxis(y);
    Legend legend = new Legend();
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setReversed(true);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ this.y");
    conf.setTooltip(tooltip);
    PlotOptionsSeries plot = new PlotOptionsSeries();
    plot.setStacking(Stacking.NORMAL);
    conf.setPlotOptions(plot);
    conf.addSeries(new ListSeries("John", 5, 3, 4, 7, 2));
    conf.addSeries(new ListSeries("Jane", 2, 2, 3, 2, 1));
    conf.addSeries(new ListSeries("Joe", 3, 4, 4, 2, 5));
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)14 Configuration (com.vaadin.addon.charts.model.Configuration)10 Chart (com.vaadin.addon.charts.Chart)8 YAxis (com.vaadin.addon.charts.model.YAxis)6 XAxis (com.vaadin.addon.charts.model.XAxis)5 DataSeries (com.vaadin.addon.charts.model.DataSeries)4 ListSeries (com.vaadin.addon.charts.model.ListSeries)4 Tooltip (com.vaadin.addon.charts.model.Tooltip)4 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)3 PlotLine (com.vaadin.addon.charts.model.PlotLine)3 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 Test (org.junit.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)2 Labels (com.vaadin.addon.charts.model.Labels)2 Legend (com.vaadin.addon.charts.model.Legend)2 ChartClickEvent (com.vaadin.addon.charts.ChartClickEvent)1 ChartClickListener (com.vaadin.addon.charts.ChartClickListener)1 PointClickEvent (com.vaadin.addon.charts.PointClickEvent)1