Search in sources :

Example 1 with ListSeries

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

the class TimeSeriesWithTimeline method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Color[] colors = getThemeColors();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setMinRange(TWO_WEEKS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    configuration.getLegend().setEnabled(false);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Exchange rate"));
    yAxis.setMin(0.6);
    yAxis.setStartOnTick(false);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setShared(true);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, (SolidColor) colors[0]);
    fillColor.addColorStop(1, (SolidColor) colors[8]);
    plotOptions.setFillColor(fillColor);
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Marker marker = plotOptions.getMarker();
    marker.setEnabled(false);
    Hover hoverState = new Hover(true);
    hoverState.setRadius(5);
    States states = new States();
    states.setHover(hoverState);
    marker.setStates(states);
    Hover hoverStateForArea = new Hover(true);
    hoverStateForArea.setLineWidth(1);
    States statesForArea = new States();
    statesForArea.setHover(hoverStateForArea);
    plotOptions.setStates(statesForArea);
    plotOptions.setShadow(false);
    configuration.setPlotOptions(plotOptions);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    ListSeries ls = new ListSeries();
    PlotOptionsArea options = new PlotOptionsArea();
    options.setPointInterval(DAY_IN_MILLIS);
    ls.setPlotOptions(options);
    ls.setName("USD to EUR");
    try {
        options.setPointStart(df.parse("2006/01/02").getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    ls.setData(USD_TO_EUR_EXCHANGE_RATES);
    configuration.setSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) Marker(com.vaadin.addon.charts.model.Marker) States(com.vaadin.addon.charts.model.States) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) ParseException(java.text.ParseException) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with ListSeries

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

the class WindRose method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.getChart().setInverted(false);
    conf.setTitle("Wind rose for South Shore Met Station, Oregon");
    conf.setSubTitle("Source: or.water.usgs.gov");
    Pane pane = new Pane();
    pane.setSize("85%");
    conf.addPane(pane);
    conf.getLegend().setReversed(false);
    conf.getLegend().setAlign(HorizontalAlign.RIGHT);
    conf.getLegend().setVerticalAlign(VerticalAlign.TOP);
    conf.getLegend().setY(100);
    conf.getLegend().setLayout(LayoutDirection.VERTICAL);
    XAxis axis = new XAxis();
    axis.setCategories("< 0.5 m/s", "0.5-2 m/s", "2-4 m/s", "4-6 m/s", "6-8 m/s", "8-10 m/s", "> 10 m/s");
    axis.setTickmarkPlacement(TickmarkPlacement.ON);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setEndOnTick(false);
    yAxis.setShowLastLabel(true);
    yAxis.setTitle(new AxisTitle("Frequency (%)"));
    Labels labels = new Labels();
    labels.setFormatter("function() {return this.value + '%';}");
    yAxis.setLabels(labels);
    conf.addxAxis(axis);
    conf.addyAxis(yAxis);
    conf.getTooltip().setValueSuffix("%");
    PlotOptionsColumn series = new PlotOptionsColumn();
    series.setStacking(Stacking.NORMAL);
    series.setShadow(false);
    series.setGroupPadding(0);
    series.setPointPlacement(PointPlacement.ON);
    conf.setPlotOptions(series);
    ListSeries n = new ListSeries("N", 1.81, 1.78, 0.16, 0.00, 0.00, 0.00, 0.00);
    ListSeries nne = new ListSeries("NNE", 0.62, 1.09, 0.00, 0.00, 0.00, 0.00, 0.00);
    ListSeries ne = new ListSeries("NE", 0.82, 0.82, 0.07, 0.00, 0.00, 0.00, 0.00);
    ListSeries ene = new ListSeries("ENE", 0.59, 1.22, 0.07, 0.00, 0.00, 0.00, 0.00);
    ListSeries e = new ListSeries("E", 0.62, 2.20, 0.49, 0.00, 0.00, 0.00, 0.00);
    ListSeries ese = new ListSeries("ESE", 1.22, 2.01, 1.55, 0.30, 0.13, 0.00, 0.00);
    ListSeries se = new ListSeries("SE", 1.61, 3.06, 2.37, 2.14, 1.74, 0.39, 0.13);
    ListSeries sse = new ListSeries("SSE", 2.04, 3.42, 1.97, 0.86, 0.53, 0.49, 0.00);
    ListSeries s = new ListSeries("S", 2.66, 4.74, 0.43, 0.00, 0.00, 0.00, 0.00);
    ListSeries ssw = new ListSeries("SSW", 2.96, 4.14, 0.26, 0.00, 0.00, 0.00, 0.00);
    ListSeries sw = new ListSeries("SW", 2.53, 4.01, 1.22, 0.49, 0.13, 0.00, 0.00);
    ListSeries wsw = new ListSeries("WSW", 1.97, 2.66, 1.97, 0.79, 0.30, 0.00, 0.00);
    ListSeries w = new ListSeries("W", 1.64, 1.71, 0.92, 1.45, 0.26, 0.10, 0.00);
    ListSeries wnw = new ListSeries("WNW", 1.32, 2.40, 0.99, 1.61, 0.33, 0.00, 0.00);
    ListSeries nw = new ListSeries("NW", 1.58, 4.28, 1.28, 0.76, 0.66, 0.69, 0.03);
    ListSeries nnw = new ListSeries("NNW", 1.51, 5.00, 1.32, 0.13, 0.23, 0.13, 0.07);
    conf.setSeries(n, nne, ne, ene, e, ese, se, sse, s, ssw, sw, wsw, w, wnw, nw, nnw);
    // transpose data "matrix"
    conf.reverseListSeries();
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with ListSeries

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

the class SVGGeneratorTest method createConf.

private Configuration createConf() {
    Configuration conf = new Configuration();
    conf.setTitle("Historic World Population by Region");
    conf.setSubTitle("Source: Wikipedia.org");
    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    x.setTitle(new AxisTitle((String) null));
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    AxisTitle title = new AxisTitle("Population (millions)");
    title.setAlign(VerticalAlign.HIGH);
    y.setTitle(title);
    conf.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    // tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
    conf.setTooltip(tooltip);
    PlotOptionsBar plot = new PlotOptionsBar();
    plot.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(plot);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-100);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBorderWidth(1);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setShadow(true);
    conf.setLegend(legend);
    conf.disableCredits();
    List<Series> series = new ArrayList<Series>();
    series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
    series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
    series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
    conf.setSeries(series);
    return conf;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) ArrayList(java.util.ArrayList) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsBar(com.vaadin.addon.charts.model.PlotOptionsBar) XAxis(com.vaadin.addon.charts.model.XAxis) Series(com.vaadin.addon.charts.model.Series) ListSeries(com.vaadin.addon.charts.model.ListSeries) TreeSeries(com.vaadin.addon.charts.model.TreeSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with ListSeries

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

the class Basic3DColumn method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Monthly Average Rainfall");
    conf.setSubTitle("Source: WorldClimate.com");
    XAxis x = new XAxis();
    x.setCategories("Jan", "Feb", "Mar", "Apr");
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    conf.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.x +': '+ this.y +' mm'");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plot = new PlotOptionsColumn();
    plot.setPointPadding(0.2);
    plot.setBorderWidth(0);
    plot.setGroupZPadding(10);
    conf.setPlotOptions(plot);
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(5);
    options3d.setBeta(30);
    options3d.setDepth(100);
    options3d.setViewDistance(200);
    Frame frame = new Frame();
    options3d.setFrame(frame);
    conf.getChart().setOptions3d(options3d);
    conf.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2));
    conf.addSeries(new ListSeries("New York", 83.6, 78.8, 98.5, 93.4));
    conf.addSeries(new ListSeries("London", 48.9, 38.8, 39.3, 41.4));
    conf.addSeries(new ListSeries("Berlin", 42.4, 33.2, 34.5, 39.7));
    chart.drawChart(conf);
    return chart;
}
Also used : Frame(com.vaadin.addon.charts.model.Frame) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) 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 ListSeries

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

the class SerializationTest method serializeChart_configurationWithSeries_seriesConfigLinkSerializedCorrectly.

@Test
public void serializeChart_configurationWithSeries_seriesConfigLinkSerializedCorrectly() throws IOException, ClassNotFoundException {
    Chart input = new Chart();
    ListSeries series = new ListSeries();
    input.getConfiguration().addSeries(series);
    Chart output = serializeObject(input);
    ListSeries outputSeries = (ListSeries) output.getConfiguration().getSeries().get(0);
    assertNotNull("Series config was null after serialization", outputSeries.getConfiguration());
    assertNotNull("Series config was null after serialization", output.getConfiguration());
    assertEquals(outputSeries.getConfiguration(), output.getConfiguration());
}
Also used : ListSeries(com.vaadin.addon.charts.model.ListSeries) Chart(com.vaadin.addon.charts.Chart) Test(org.junit.Test)

Aggregations

ListSeries (com.vaadin.addon.charts.model.ListSeries)88 Chart (com.vaadin.addon.charts.Chart)76 Configuration (com.vaadin.addon.charts.model.Configuration)70 YAxis (com.vaadin.addon.charts.model.YAxis)46 XAxis (com.vaadin.addon.charts.model.XAxis)35 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)31 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)25 Tooltip (com.vaadin.addon.charts.model.Tooltip)24 Legend (com.vaadin.addon.charts.model.Legend)18 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)18 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)16 Title (com.vaadin.addon.charts.model.Title)15 Labels (com.vaadin.addon.charts.model.Labels)11 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)11 Marker (com.vaadin.addon.charts.model.Marker)10 VerticalLayout (com.vaadin.ui.VerticalLayout)9 Hover (com.vaadin.addon.charts.model.Hover)8 States (com.vaadin.addon.charts.model.States)8 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)8