Search in sources :

Example 16 with Configuration

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

the class SVGGeneratorTest method exportWithCustomWidth.

@Test
public void exportWithCustomWidth() throws IOException, InterruptedException {
    Configuration conf = createPieChartConfiguration();
    ExportOptions options = new ExportOptions();
    options.setWidth(999);
    String svg = svgGenerator.generate(conf, options);
    Path pieChartPath = Paths.get("src", "test", "resources", "custom-width.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)

Example 17 with Configuration

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

the class SVGGeneratorTest method exportWithCustomHeight.

@Test
public void exportWithCustomHeight() throws IOException, InterruptedException {
    Configuration conf = createPieChartConfiguration();
    ExportOptions options = new ExportOptions();
    options.setHeight(999);
    String svg = svgGenerator.generate(conf, options);
    Path pieChartPath = Paths.get("src", "test", "resources", "custom-height.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)

Example 18 with Configuration

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

the class SVGGeneratorTest method exportWithTimeline.

@Test
public void exportWithTimeline() throws IOException, InterruptedException {
    Configuration configuration = new Configuration();
    configuration.getChart().setType(ChartType.AREASPLINERANGE);
    configuration.getTitle().setText("Temperature variation by day");
    Tooltip tooltip = configuration.getTooltip();
    tooltip.setValueSuffix("°C");
    DataSeries dataSeries = new DataSeries("Temperatures");
    for (StockPrices.RangeData data : StockPrices.fetchDailyTempRanges()) {
        dataSeries.add(new DataSeriesItem(data.getDate(), data.getMin(), data.getMax()));
    }
    configuration.setSeries(dataSeries);
    ExportOptions options = new ExportOptions();
    options.setTimeline(true);
    Path expectedFilePath = Paths.get("src", "test", "resources", "timeline.svg");
    String expectedSVG = readUtf8File(expectedFilePath);
    String actualSVG = svgGenerator.generate(configuration, options);
    assertEquals(replaceIds(expectedSVG), replaceIds(actualSVG));
}
Also used : Path(java.nio.file.Path) 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) Test(org.junit.Test)

Example 19 with Configuration

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

the class Xrange method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.XRANGE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("X-range");
    conf.getxAxis().setType(AxisType.DATETIME);
    conf.getyAxis().setTitle("");
    conf.getyAxis().setCategories("Prototyping", "Development", "Testing");
    conf.getyAxis().setReversed(true);
    DataSeries series = new DataSeries();
    series.setName("Project 1");
    series.add(new DataSeriesItemXrange(getInstant(2014, 11, 21), getInstant(2014, 12, 2), 0, 0.25));
    series.add(new DataSeriesItemXrange(getInstant(2014, 12, 2), getInstant(2014, 12, 5), 1));
    series.add(new DataSeriesItemXrange(getInstant(2014, 12, 8), getInstant(2014, 12, 9), 2));
    series.add(new DataSeriesItemXrange(getInstant(2014, 12, 9), getInstant(2014, 12, 19), 1));
    series.add(new DataSeriesItemXrange(getInstant(2014, 12, 10), getInstant(2014, 12, 23), 2));
    PlotOptionsXrange options = new PlotOptionsXrange();
    options.setBorderColor(SolidColor.GRAY);
    options.setPointWidth(20);
    options.getDataLabels().setEnabled(true);
    series.setPlotOptions(options);
    conf.addSeries(series);
    add(chart);
}
Also used : PlotOptionsXrange(com.vaadin.flow.component.charts.model.PlotOptionsXrange) Configuration(com.vaadin.flow.component.charts.model.Configuration) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItemXrange(com.vaadin.flow.component.charts.model.DataSeriesItemXrange) Chart(com.vaadin.flow.component.charts.Chart)

Example 20 with Configuration

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

the class PieWithLegend method initDemo.

@Override
public void initDemo() {
    chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares in January, 2018");
    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);
    chart.setVisibilityTogglingDisabled(true);
    listenerRegistration = chart.addPointLegendItemClickListener(event -> {
        showNotification("Legend item click" + " : " + event.getItemIndex() + " : " + event.getItem().getName());
    });
    add(chart);
}
Also used : DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) ChartType(com.vaadin.flow.component.charts.model.ChartType) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Chart(com.vaadin.flow.component.charts.Chart) Registration(com.vaadin.flow.shared.Registration) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) AbstractChartExample(com.vaadin.flow.component.charts.examples.AbstractChartExample) Cursor(com.vaadin.flow.component.charts.model.Cursor) Configuration(com.vaadin.flow.component.charts.model.Configuration) 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) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

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