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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations