Search in sources :

Example 1 with PlotOptionsSpline

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

the class ChartDesignWriterTest method writeConfiguration_multiplePlotOptions_allPlotOptionsAreChildrenOfPlotOptionsTag.

@Test
public void writeConfiguration_multiplePlotOptions_allPlotOptionsAreChildrenOfPlotOptionsTag() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    PlotOptionsLine plotOptionsLine = new PlotOptionsLine();
    plotOptionsLine.setAnimation(false);
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setVisible(false);
    configuration.setPlotOptions(plotOptionsLine, plotOptionsSpline);
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    // Expected (the order of plot options is unknown):
    // "<plot-options>
    // <line animation=\"false\">
    // </line>
    // <spline visible=\"false\">
    // </spline>
    // </plot-options>"
    assertEquals("plot-options", parent.child(0).tagName());
    Elements plotOptions = parent.child(0).children();
    assertEquals(2, plotOptions.size());
    assertPlotOptions("line", "animation", "false", plotOptions);
    assertPlotOptions("spline", "visible", "false", plotOptions);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 2 with PlotOptionsSpline

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

the class ChartDesignReaderTest method readConfiguration_multiplePlotOptions_attributesAreReadToCorrectPlotOptions.

@Test
public void readConfiguration_multiplePlotOptions_attributesAreReadToCorrectPlotOptions() {
    Elements elements = createElements("<plot-options>" + "<line animation=\"true\"></line>" + "<spline animation=\"false\"></spline>" + "</plot-options>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    PlotOptionsLine line = (PlotOptionsLine) configuration.getPlotOptions(ChartType.LINE);
    PlotOptionsSpline spline = (PlotOptionsSpline) configuration.getPlotOptions(ChartType.SPLINE);
    assertFalse(spline.getAnimation());
    assertTrue(line.getAnimation());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) Elements(org.jsoup.select.Elements) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) Test(org.junit.Test)

Example 3 with PlotOptionsSpline

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

the class SplineWithPlotBands method getChart.

@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Wind speed during two days");
    configuration.getSubTitle().setText("October 6th and 7th 2009 at two locations in Vik i Sogn, Norway");
    configuration.getxAxis().setType(AxisType.DATETIME);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Wind speed (m/s)"));
    yAxis.setMin(0);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setGridLineWidth(0);
    // disable alternate grid color from Vaadin theme, disturbs
    // demonstrating plotbands
    yAxis.setAlternateGridColor(TRANSPARENT);
    Style style = new Style();
    style.setColor(LIGHT_GRAY);
    final PlotBand lightAir = new PlotBand();
    lightAir.setFrom(0.3);
    lightAir.setTo(1.5);
    lightAir.setColor(LIGHT_BLUE);
    lightAir.setLabel(new Label("Light air"));
    lightAir.getLabel().setStyle(style);
    final PlotBand lightBreeze = new PlotBand();
    lightBreeze.setFrom(1.5);
    lightBreeze.setTo(3.3);
    lightBreeze.setColor(TRANSPARENT);
    lightBreeze.setLabel(new Label("Light breeze"));
    lightBreeze.getLabel().setStyle(style);
    final PlotBand gentleBreeze = new PlotBand();
    gentleBreeze.setFrom(3.3);
    gentleBreeze.setTo(5.5);
    gentleBreeze.setColor(LIGHT_BLUE);
    gentleBreeze.setLabel(new Label("Gentle breeze"));
    gentleBreeze.getLabel().setStyle(style);
    final PlotBand moderateBreeze = new PlotBand();
    moderateBreeze.setFrom(5.5);
    moderateBreeze.setTo(8);
    moderateBreeze.setColor(TRANSPARENT);
    moderateBreeze.setLabel(new Label("Moderate breeze"));
    moderateBreeze.getLabel().setStyle(style);
    final PlotBand freshBreeze = new PlotBand();
    freshBreeze.setFrom(8);
    freshBreeze.setTo(11);
    freshBreeze.setColor(LIGHT_BLUE);
    freshBreeze.setLabel(new Label("Fresh breeze"));
    freshBreeze.getLabel().setStyle(style);
    final PlotBand strongBreeze = new PlotBand();
    strongBreeze.setFrom(11);
    strongBreeze.setTo(14);
    strongBreeze.setColor(TRANSPARENT);
    strongBreeze.setLabel(new Label("Strong breeze"));
    strongBreeze.getLabel().setStyle(style);
    final PlotBand highWind = new PlotBand();
    highWind.setFrom(14);
    highWind.setTo(15);
    highWind.setColor(LIGHT_BLUE);
    highWind.setLabel(new Label("High wind"));
    highWind.getLabel().setStyle(style);
    yAxis.setPlotBands(lightAir, lightBreeze, gentleBreeze, moderateBreeze, freshBreeze, strongBreeze, highWind);
    configuration.getTooltip().setFormatter("Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y +' m/s'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(false));
    plotOptions.getMarker().setLineWidth(4);
    plotOptions.getMarker().setSymbol(MarkerSymbolEnum.CIRCLE);
    States states = new States();
    Hover hover = new Hover(true);
    hover.setRadius(5);
    hover.setLineWidth(1);
    states.setHover(hover);
    plotOptions.getMarker().setStates(states);
    plotOptions.setPointInterval(ONE_HOUR);
    LocalDate date = LocalDate.of(2009, 9, 6);
    plotOptions.setPointStart(date.atStartOfDay().toInstant(ZoneOffset.UTC));
    ListSeries ls = new ListSeries();
    ls.setName("Hestavollane");
    ls.setData(4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1, 7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4, 8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5, 7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2, 3.0, 3.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Voll");
    ls.setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0, 0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3, 3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Label(com.vaadin.addon.charts.model.Label) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) LocalDate(java.time.LocalDate) States(com.vaadin.addon.charts.model.States) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) Style(com.vaadin.addon.charts.model.style.Style) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with PlotOptionsSpline

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

the class SplineWithSymbols method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Temperature"));
    Labels labels = new Labels();
    labels.setFormatter("this.value +'°'");
    yAxis.setLabels(labels);
    configuration.getTooltip().setShared(true);
    configuration.getxAxis().setCrosshair(new Crosshair());
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(true));
    plotOptions.getMarker().setRadius(4);
    plotOptions.getMarker().setLineColor(new SolidColor("#666666"));
    plotOptions.getMarker().setLineWidth(1);
    DataSeries ls = new DataSeries();
    plotOptions = new PlotOptionsSpline();
    Marker marker = new Marker();
    marker.setSymbol(MarkerSymbolEnum.SQUARE);
    plotOptions.setMarker(marker);
    ls.setPlotOptions(plotOptions);
    ls.setName("Tokyo");
    ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    ls.get("26.5").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/sun.png"));
    configuration.addSeries(ls);
    ls = new DataSeries();
    plotOptions = new PlotOptionsSpline();
    marker = new Marker();
    marker.setSymbol(MarkerSymbolEnum.DIAMOND);
    plotOptions.setMarker(marker);
    ls.setPlotOptions(plotOptions);
    ls.setName("London");
    ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
    ls.get("3.9").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/snow.png"));
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : MarkerSymbolUrl(com.vaadin.addon.charts.model.MarkerSymbolUrl) Configuration(com.vaadin.addon.charts.model.Configuration) Crosshair(com.vaadin.addon.charts.model.Crosshair) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 5 with PlotOptionsSpline

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

the class TimeDataWithIrregularIntervals method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Snow depth in the Vikjafjellet mountain, Norway");
    configuration.getSubTitle().setText("An example of irregular time data in Highcharts JS");
    configuration.getTooltip().setFormatter("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats("%e. %b", "%b"));
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Snow depth (m)"));
    yAxis.setMin(0);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>\'+ Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m'");
    DataSeries ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2007-2008");
    Object[][] data1 = getData1();
    for (int i = 0; i < data1.length; i++) {
        Object[] ds = data1[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2008-2009");
    Object[][] data2 = getData2();
    for (int i = 0; i < data2.length; i++) {
        Object[] ds = data2[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2009-2010");
    Object[][] data3 = getData3();
    for (int i = 0; i < data3.length; i++) {
        Object[] ds = data3[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) DataSeries(com.vaadin.addon.charts.model.DataSeries) DateTimeLabelFormats(com.vaadin.addon.charts.model.DateTimeLabelFormats) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)20 Configuration (com.vaadin.addon.charts.model.Configuration)18 Chart (com.vaadin.addon.charts.Chart)16 DataSeries (com.vaadin.addon.charts.model.DataSeries)14 YAxis (com.vaadin.addon.charts.model.YAxis)14 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)8 XAxis (com.vaadin.addon.charts.model.XAxis)8 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)8 Marker (com.vaadin.addon.charts.model.Marker)7 Style (com.vaadin.addon.charts.model.style.Style)6 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)5 Labels (com.vaadin.addon.charts.model.Labels)4 Legend (com.vaadin.addon.charts.model.Legend)4 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)4 PlotLine (com.vaadin.addon.charts.model.PlotLine)3 Tooltip (com.vaadin.addon.charts.model.Tooltip)3 Color (com.vaadin.addon.charts.model.style.Color)3 Random (java.util.Random)3 DateTimeLabelFormats (com.vaadin.addon.charts.model.DateTimeLabelFormats)2