Search in sources :

Example 26 with DataSeriesItem

use of com.vaadin.flow.component.charts.model.DataSeriesItem 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)

Example 27 with DataSeriesItem

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

the class Spline method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.SPLINE);
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    configuration.getTooltip().setEnabled(true);
    DataSeries dataSeries = new DataSeries();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        dataSeries.add(item);
    }
    configuration.addSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    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) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 28 with DataSeriesItem

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

the class SVGGeneratorTest method createPieChartConfiguration.

private Configuration createPieChartConfiguration() {
    Configuration conf = new Configuration();
    conf.setTitle("Browser market shares in January, 2018");
    conf.getChart().setType(ChartType.PIE);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueDecimals(1);
    conf.setTooltip(tooltip);
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setAllowPointSelect(true);
    plotOptions.setCursor(Cursor.POINTER);
    plotOptions.setShowInLegend(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 61.41);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Internet Explorer", 11.84));
    series.add(new DataSeriesItem("Firefox", 10.85));
    series.add(new DataSeriesItem("Edge", 4.67));
    series.add(new DataSeriesItem("Safari", 4.18));
    series.add(new DataSeriesItem("Sogou Explorer", 1.64));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("QQ", 1.2));
    series.add(new DataSeriesItem("Others", 2.61));
    conf.setSeries(series);
    return conf;
}
Also used : PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 29 with DataSeriesItem

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

the class HasItemTest method getItemWithDataSeries.

@Test
public void getItemWithDataSeries() {
    Chart chart = new Chart();
    DataSeriesItem item = new DataSeriesItem(5, 10);
    DataSeries series = new DataSeries(item);
    chart.getConfiguration().addSeries(series);
    HasItem hasItem = new HasItemTestImpl(chart, 0, 0);
    DataSeriesItem result = hasItem.getItem();
    Assert.assertEquals(item, result);
}
Also used : HasItem(com.vaadin.flow.component.charts.events.HasItem) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) Test(org.junit.Test)

Aggregations

DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)29 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)26 Chart (com.vaadin.flow.component.charts.Chart)20 Configuration (com.vaadin.flow.component.charts.model.Configuration)20 XAxis (com.vaadin.flow.component.charts.model.XAxis)10 YAxis (com.vaadin.flow.component.charts.model.YAxis)10 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)9 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)6 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)5 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)4 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)3 ChartType (com.vaadin.flow.component.charts.model.ChartType)3 DataLabelsFunnel (com.vaadin.flow.component.charts.model.DataLabelsFunnel)3 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)3 PlotOptionsPie (com.vaadin.flow.component.charts.model.PlotOptionsPie)3 PlotOptionsScatter (com.vaadin.flow.component.charts.model.PlotOptionsScatter)3 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)3 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)2 Cursor (com.vaadin.flow.component.charts.model.Cursor)2 Legend (com.vaadin.flow.component.charts.model.Legend)2