Search in sources :

Example 66 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration 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 67 with Configuration

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

the class SVGGeneratorTest method createAreaChartConfiguration.

private Configuration createAreaChartConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setTitle("First Chart for Flow");
    configuration.getChart().setType(ChartType.AREA);
    Tooltip tooltip = configuration.getTooltip();
    tooltip.setEnabled(true);
    tooltip.setShared(true);
    PlotOptionsSeries options = new PlotOptionsSeries();
    options.setPointStart(0);
    options.setPointIntervalUnit(IntervalUnit.DAY);
    configuration.setPlotOptions(options);
    configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
    configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
    XAxis x = new XAxis();
    x.setType(AxisType.DATETIME);
    x.getLabels().setFormat("{value:%a}");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    configuration.addyAxis(y);
    return configuration;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 68 with Configuration

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

the class SVGGeneratorTest method exportWithCustomLang.

@Test
public void exportWithCustomLang() throws IOException, InterruptedException {
    Configuration conf = createAreaChartConfiguration();
    ExportOptions options = new ExportOptions();
    Lang lang = createLang();
    options.setLang(lang);
    String svg = svgGenerator.generate(conf, options);
    Path pieChartPath = Paths.get("src", "test", "resources", "custom-lang.svg");
    String expectedSVG = readUtf8File(pieChartPath);
    assertEquals(replaceIds(expectedSVG), replaceIds(svg));
}
Also used : Path(java.nio.file.Path) Configuration(com.vaadin.flow.component.charts.model.Configuration) Lang(com.vaadin.flow.component.charts.model.Lang) Test(org.junit.Test)

Example 69 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration 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 70 with Configuration

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

the class SVGGeneratorTest method generateSVGFromChartWithoutTitle.

@Test
public void generateSVGFromChartWithoutTitle() throws IOException, InterruptedException {
    Configuration conf = createColumnWithoutTitle();
    String svg = svgGenerator.generate(conf);
    Path pieChartPath = Paths.get("src", "test", "resources", "column-without-title.svg");
    String expectedSVG = readUtf8File(pieChartPath);
    assertEquals(replaceIds(expectedSVG), replaceIds(svg));
}
Also used : Path(java.nio.file.Path) Configuration(com.vaadin.flow.component.charts.model.Configuration) Test(org.junit.Test)

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