Search in sources :

Example 6 with YAxis

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

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

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

the class SerializationTest method serializeChart_configurationWithAxis_axisConfigLinkSerializedCorrectly.

@Test
public void serializeChart_configurationWithAxis_axisConfigLinkSerializedCorrectly() throws IOException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
    Chart input = new Chart();
    YAxis axis = new YAxis();
    axis.setConfiguration(input.getConfiguration());
    input.getConfiguration().addyAxis(axis);
    Chart output = serializeObject(input);
    YAxis outputAxis = output.getConfiguration().getyAxis();
    assertNotNull("Axis config was null after serialization", getPrivateField("configuration", outputAxis, Axis.class));
    assertNotNull("Axis config was null after serialization", output.getConfiguration());
    assertEquals(getPrivateField("configuration", outputAxis, Axis.class), output.getConfiguration());
}
Also used : Chart(com.vaadin.addon.charts.Chart) Axis(com.vaadin.addon.charts.model.Axis) YAxis(com.vaadin.addon.charts.model.YAxis) YAxis(com.vaadin.addon.charts.model.YAxis) Test(org.junit.Test)

Example 9 with YAxis

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

the class AxisJSONSerializationTest method toJSON_heightSetAsPercentage_heightSerializedAsString.

@Test
public void toJSON_heightSetAsPercentage_heightSerializedAsString() {
    YAxis axis = new YAxis();
    axis.setHeight(50, Unit.PERCENTAGE);
    String json = toJSON(axis);
    String expected = "{\"height\":\"50.0%\"}";
    assertEquals(expected, json);
}
Also used : YAxis(com.vaadin.addon.charts.model.YAxis) Test(org.junit.Test)

Example 10 with YAxis

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

Aggregations

YAxis (com.vaadin.addon.charts.model.YAxis)115 Chart (com.vaadin.addon.charts.Chart)105 Configuration (com.vaadin.addon.charts.model.Configuration)100 XAxis (com.vaadin.addon.charts.model.XAxis)63 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)51 ListSeries (com.vaadin.addon.charts.model.ListSeries)46 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)40 DataSeries (com.vaadin.addon.charts.model.DataSeries)39 Tooltip (com.vaadin.addon.charts.model.Tooltip)39 DataLabels (com.vaadin.addon.charts.model.DataLabels)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)28 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)27 Legend (com.vaadin.addon.charts.model.Legend)24 Labels (com.vaadin.addon.charts.model.Labels)19 Marker (com.vaadin.addon.charts.model.Marker)16 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)14 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)13 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)13 Title (com.vaadin.addon.charts.model.Title)13 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)13