Search in sources :

Example 61 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class Timeline method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.TIMELINE);
    Configuration conf = chart.getConfiguration();
    conf.getxAxis().setVisible(false);
    conf.getyAxis().setVisible(false);
    conf.setTitle("Timeline of Space Exploration");
    conf.setSubTitle("Info source: <a href=\"https://en.wikipedia.org/wiki/Timeline_of_space_exploration\">www.wikipedia.org</a>");
    conf.getTooltip().setEnabled(true);
    DataSeries series = new DataSeries();
    series.add(new DataSeriesItemTimeline("First dogs", "1951: First dogs in space", "22 July 1951 First dogs in space (Dezik and Tsygan)"));
    series.add(new DataSeriesItemTimeline("Sputnik 1", "1957: First artificial satellite", "4 October 1957 First artificial satellite. First signals from space."));
    series.add(new DataSeriesItemTimeline("First human spaceflight", "1961: First human spaceflight (Yuri Gagarin)", "First human spaceflight (Yuri Gagarin), and the first human-crewed orbital flight"));
    series.add(new DataSeriesItemTimeline("First human on the Moon", "1969: First human on the Moon", "First human on the Moon, and first space launch from a celestial body other than the Earth. First sample return from the Moon"));
    conf.addSeries(series);
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItemTimeline(com.vaadin.flow.component.charts.model.DataSeriesItemTimeline) Chart(com.vaadin.flow.component.charts.Chart)

Example 62 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class Treemap method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.TREEMAP);
    Configuration conf = chart.getConfiguration();
    conf.getTooltip().setEnabled(true);
    PlotOptionsTreemap plotOptions = new PlotOptionsTreemap();
    plotOptions.setLayoutAlgorithm(TreeMapLayoutAlgorithm.STRIPES);
    plotOptions.setAlternateStartingDirection(true);
    Level level1 = new Level();
    level1.setLevel(1);
    level1.setLayoutAlgorithm(TreeMapLayoutAlgorithm.SLICEANDDICE);
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setAlign(HorizontalAlign.LEFT);
    dataLabels.setVerticalAlign(VerticalAlign.TOP);
    level1.setDataLabels(dataLabels);
    plotOptions.setLevels(level1);
    TreeSeries series = createSeries();
    series.setPlotOptions(plotOptions);
    chart.getConfiguration().addSeries(series);
    chart.getConfiguration().setTitle("Fruit consumption");
    add(chart);
}
Also used : TreeSeries(com.vaadin.flow.component.charts.model.TreeSeries) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsTreemap(com.vaadin.flow.component.charts.model.PlotOptionsTreemap) Level(com.vaadin.flow.component.charts.model.Level) Chart(com.vaadin.flow.component.charts.Chart)

Example 63 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class WindRose method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.setTitle("Wind rose for South Shore Met Station, Oregon");
    conf.setSubTitle("Source: or.water.usgs.gov");
    XAxis xAxis = conf.getxAxis();
    xAxis.setCategories("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
    YAxis yAxis = conf.getyAxis();
    yAxis.setReversedStacks(false);
    yAxis.setTitle("Frequency (%)");
    yAxis.setMin(0);
    yAxis.setEndOnTick(false);
    yAxis.setShowLastLabel(true);
    yAxis.getLabels().setFormatter("function() { return this.value + '%';}");
    conf.getTooltip().setValueSuffix("%");
    conf.getPane().setSize("85%");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setStacking(Stacking.NORMAL);
    plotOptionsColumn.setGroupPadding(0);
    plotOptionsColumn.setPointPlacement(PointPlacement.ON);
    conf.setPlotOptions(plotOptionsColumn);
    Legend legend = conf.getLegend();
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(100);
    legend.setLayout(LayoutDirection.VERTICAL);
    DataSeries series = new DataSeries();
    series.setName("&lt; 0.5 m/s");
    series.setData(1.81, 0.62, 0.82, 0.59, 0.62, 1.22, 1.61, 2.04, 2.66, 2.96, 2.53, 1.97, 1.64, 1.32, 1.58, 1.51);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("0.5-2 m/s");
    series.setData(1.78, 1.09, 0.82, 1.22, 2.2, 2.01, 3.06, 3.42, 4.74, 4.14, 4.01, 2.66, 1.71, 2.4, 4.28, 5);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("2-4 m/s");
    series.setData(0.16, 0, 0.07, 0.07, 0.49, 1.55, 2.37, 1.97, 0.43, 0.26, 1.22, 1.97, 0.92, 0.99, 1.28, 1.32);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("4-6 m/s");
    series.setData(0, 0, 0, 0, 0, 0.3, 2.14, 0.86, 0, 0, 0.49, 0.79, 1.45, 1.61, 0.76, 0.13);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("6-8 m/s");
    series.setData(0, 0, 0, 0, 0, 0.13, 1.74, 0.53, 0, 0, 0.13, 0.3, 0.26, 0.33, 0.66, 0.23);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("8-10 m/s");
    series.setData(0, 0, 0, 0, 0, 0, 0.39, 0.49, 0, 0, 0, 0, 0.1, 0, 0.69, 0.13);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("&gt; 10 m/s");
    series.setData(0, 0, 0, 0, 0, 0, 0.13, 0, 0, 0, 0, 0, 0, 0, 0.03, 0.07);
    conf.addSeries(series);
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 64 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class ColumnRange method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("Temperature variation by day");
    DataSeries dataSeries = new DataSeries("Temperatures");
    for (StockPrices.RangeData data : StockPrices.fetchDailyTempRanges()) {
        dataSeries.add(new DataSeriesItem(data.getDate(), data.getMin(), data.getMax()));
    }
    configuration.setSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(2);
    configuration.setRangeSelector(rangeSelector);
    chart.setTimeline(true);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 65 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class CompareMultipleSeries method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("function() { return (this.value > 0 ? ' + ' : '') + this.value + '%'; }");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span>{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(Compare.PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Labels(com.vaadin.flow.component.charts.model.Labels) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)72 Chart (com.vaadin.flow.component.charts.Chart)48 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)32 YAxis (com.vaadin.flow.component.charts.model.YAxis)32 XAxis (com.vaadin.flow.component.charts.model.XAxis)25 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)24 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)20 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)19 Test (org.junit.Test)16 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)12 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)10 Path (java.nio.file.Path)10 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)9 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 Labels (com.vaadin.flow.component.charts.model.Labels)7 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)6 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)5 Pane (com.vaadin.flow.component.charts.model.Pane)4