Search in sources :

Example 16 with Chart

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

the class Candlestick method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.CANDLESTICK);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    PlotOptionsCandlestick plotOptionsCandlestick = new PlotOptionsCandlestick();
    DataGrouping grouping = new DataGrouping();
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
    plotOptionsCandlestick.setDataGrouping(grouping);
    dataSeries.setPlotOptions(plotOptionsCandlestick);
    for (StockPrices.OhlcData data : StockPrices.fetchAaplOhlcPrice()) {
        OhlcItem item = new OhlcItem();
        item.setX(data.getDate());
        item.setLow(data.getLow());
        item.setHigh(data.getHigh());
        item.setClose(data.getClose());
        item.setOpen(data.getOpen());
        dataSeries.add(item);
    }
    configuration.setSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    chart.setTimeline(true);
    add(chart);
}
Also used : PlotOptionsCandlestick(com.vaadin.flow.component.charts.model.PlotOptionsCandlestick) StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) TimeUnitMultiples(com.vaadin.flow.component.charts.model.TimeUnitMultiples) OhlcItem(com.vaadin.flow.component.charts.model.OhlcItem) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataGrouping(com.vaadin.flow.component.charts.model.DataGrouping) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart)

Example 17 with Chart

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

the class AreaRange method initDemo.

@Override
public void initDemo() {
    chart = new Chart(ChartType.AREARANGE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Temperature variation by day");
    conf.getxAxis().setType(AxisType.DATETIME);
    conf.getxAxis().setCrosshair(new Crosshair());
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    tooltip.setValueSuffix("°C");
    conf.setTooltip(tooltip);
    RangeSeries data = new RangeSeries("Temperatures", getRawData());
    conf.setSeries(data);
    chart.drawChart();
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSeries(com.vaadin.flow.component.charts.model.RangeSeries) Crosshair(com.vaadin.flow.component.charts.model.Crosshair) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Chart(com.vaadin.flow.component.charts.Chart)

Example 18 with Chart

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

the class Bubble method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.BUBBLE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle((String) null);
    DataSeries dataSeries = new DataSeries("All bubbles shown");
    dataSeries.add(item(9, 81, 13));
    dataSeries.add(item(98, 5, 39));
    dataSeries.add(item(51, 50, 23));
    dataSeries.add(item(41, 22, -36));
    dataSeries.add(item(58, 24, -30));
    dataSeries.add(item(78, 37, -16));
    dataSeries.add(item(55, 56, 3));
    dataSeries.add(item(18, 45, 20));
    dataSeries.add(item(42, 44, -22));
    dataSeries.add(item(3, 52, 9));
    dataSeries.add(item(31, 18, 47));
    dataSeries.add(item(79, 91, 13));
    dataSeries.add(item(93, 23, -27));
    dataSeries.add(item(44, 83, -28));
    PlotOptionsBubble opts = new PlotOptionsBubble();
    opts.setMaxSize("120");
    opts.setMinSize("3");
    conf.setPlotOptions(opts);
    conf.addSeries(dataSeries);
    DataSeries dataSeries2 = new DataSeries("Negative bubbles hidden");
    dataSeries2.add(item(13, 30, 10));
    dataSeries2.add(item(23, 20, -10));
    dataSeries2.add(item(23, 40, 10));
    opts = new PlotOptionsBubble();
    opts.setDisplayNegative(false);
    dataSeries2.setPlotOptions(opts);
    conf.addSeries(dataSeries2);
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsBubble(com.vaadin.flow.component.charts.model.PlotOptionsBubble) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart)

Example 19 with Chart

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

the class OHLC method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.OHLC);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    PlotOptionsOhlc plotOptionsOhlc = new PlotOptionsOhlc();
    DataGrouping grouping = new DataGrouping();
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
    plotOptionsOhlc.setDataGrouping(grouping);
    dataSeries.setPlotOptions(plotOptionsOhlc);
    for (StockPrices.OhlcData data : StockPrices.fetchAaplOhlcPrice()) {
        OhlcItem item = new OhlcItem();
        item.setX(data.getDate());
        item.setLow(data.getLow());
        item.setHigh(data.getHigh());
        item.setClose(data.getClose());
        item.setOpen(data.getOpen());
        dataSeries.add(item);
    }
    configuration.setSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    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) TimeUnitMultiples(com.vaadin.flow.component.charts.model.TimeUnitMultiples) OhlcItem(com.vaadin.flow.component.charts.model.OhlcItem) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataGrouping(com.vaadin.flow.component.charts.model.DataGrouping) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsOhlc(com.vaadin.flow.component.charts.model.PlotOptionsOhlc) Chart(com.vaadin.flow.component.charts.Chart)

Example 20 with Chart

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

the class AreaSpline method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Average fruit consumption during one week"));
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    conf.setLegend(legend);
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" });
    PlotBand plotBand = new PlotBand(4.5, 6.5, SolidColor.BLUE);
    plotBand.setZIndex(1);
    xAxis.setPlotBands(plotBand);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle(new AxisTitle("Fruit units"));
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    // Customize tooltip formatting
    tooltip.setShared(true);
    tooltip.setValueSuffix(" units");
    conf.setTooltip(tooltip);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    conf.setPlotOptions(plotOptions);
    ListSeries o = new ListSeries("John", 3, 4, 3, 5, 4, 10);
    // You can also add values separately
    o.addData(12);
    conf.addSeries(o);
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsArea(com.vaadin.flow.component.charts.model.PlotOptionsArea) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Title(com.vaadin.flow.component.charts.model.Title) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) PlotBand(com.vaadin.flow.component.charts.model.PlotBand) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)57 Configuration (com.vaadin.flow.component.charts.model.Configuration)48 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)32 YAxis (com.vaadin.flow.component.charts.model.YAxis)31 XAxis (com.vaadin.flow.component.charts.model.XAxis)26 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)20 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)20 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)17 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)15 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)13 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)6 Labels (com.vaadin.flow.component.charts.model.Labels)6 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)6 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)6 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 ChartType (com.vaadin.flow.component.charts.model.ChartType)4 SolidColor (com.vaadin.flow.component.charts.model.style.SolidColor)4 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)3