Search in sources :

Example 36 with Configuration

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

the class ChartDesignReaderTest method readConfiguration_titleWithStyleAsInnerElement_theTitleAndStyleAreInConfiguration.

@Test
public void readConfiguration_titleWithStyleAsInnerElement_theTitleAndStyleAreInConfiguration() {
    Elements elements = createElements("<chart-title text=\"foobar\"><chart-style top=\"12\"></chart-style></chart-title>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals("12", configuration.getTitle().getStyle().getTop());
    assertEquals("foobar", configuration.getTitle().getText());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 37 with Configuration

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

the class ChartDesignReaderTest method readConfiguration_multiValueNodes_allTheNodesAreInTheConfiguration.

@Test
public void readConfiguration_multiValueNodes_allTheNodesAreInTheConfiguration() {
    Elements elements = createElements("<y-axis><chart-title>First</chart-title></y-axis>" + "<y-axis><chart-title>Second</chart-title></y-axis>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals(2, configuration.getyAxes().getNumberOfAxes());
    assertEquals("First", configuration.getyAxis(0).getTitle().getText());
    assertEquals("Second", configuration.getyAxis(1).getTitle().getText());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 38 with Configuration

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

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

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

Configuration (com.vaadin.addon.charts.model.Configuration)257 Chart (com.vaadin.addon.charts.Chart)196 YAxis (com.vaadin.addon.charts.model.YAxis)100 DataSeries (com.vaadin.addon.charts.model.DataSeries)72 ListSeries (com.vaadin.addon.charts.model.ListSeries)70 XAxis (com.vaadin.addon.charts.model.XAxis)65 Test (org.junit.Test)58 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)56 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)54 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)51 Tooltip (com.vaadin.addon.charts.model.Tooltip)42 DataLabels (com.vaadin.addon.charts.model.DataLabels)41 Legend (com.vaadin.addon.charts.model.Legend)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)30 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)27 Elements (org.jsoup.select.Elements)27 Marker (com.vaadin.addon.charts.model.Marker)22 DesignContext (com.vaadin.ui.declarative.DesignContext)22 Element (org.jsoup.nodes.Element)22 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)20