use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class ColumnWithNegativeValues method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle(new Title("Column chart with negative values"));
PlotOptionsColumn column = new PlotOptionsColumn();
column.setMinPointLength(3);
conf.setPlotOptions(column);
XAxis xAxis = new XAxis();
xAxis.setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
conf.addxAxis(xAxis);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("function() { return ''+ this.series.name +': '+ this.y +'';}");
conf.setTooltip(tooltip);
conf.setCredits(new Credits(false));
conf.addSeries(new ListSeries("John", 5, 0.1, 4, 7, 2));
conf.addSeries(new ListSeries("Jane", 2, -2, -0.1, 2, 1));
conf.addSeries(new ListSeries("Joe", 3, 4, 4, -2, 5));
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class MultipleAxes method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.getChart().setZoomType(Dimension.XY);
conf.setTitle("Average Monthly Weather Data for Tokyo");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
conf.addxAxis(x);
YAxis y1 = new YAxis();
y1.setShowEmpty(false);
y1.setTitle(new AxisTitle("Temperature"));
Labels labels = new Labels();
labels.setFormatter("return this.value +'°C'");
y1.setLabels(labels);
y1.setOpposite(true);
y1.setClassName("y1");
conf.addyAxis(y1);
YAxis y2 = new YAxis();
y2.setShowEmpty(false);
y2.setTitle(new AxisTitle("Rainfall"));
labels = new Labels();
labels.setFormatter("return this.value +' mm'");
y2.setLabels(labels);
y2.setClassName("y2");
conf.addyAxis(y2);
YAxis y3 = new YAxis();
y3.setShowEmpty(false);
y3.setTitle(new AxisTitle("Sea-Level Pressure"));
labels = new Labels();
labels.setFormatter("return this.value +' mb'");
y3.setLabels(labels);
y3.setOpposite(true);
y3.setClassName("y3");
conf.addyAxis(y3);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("function() { " + "var unit = { 'Rainfall': 'mm', 'Temperature': '°C', 'Sea-Level Pressure': 'mb' }[this.series.name];" + "return ''+ this.x +': '+ this.y +' '+ unit; }");
conf.setTooltip(tooltip);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setX(120);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setY(80);
legend.setFloating(true);
conf.setLegend(legend);
DataSeries series = new DataSeries();
PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
series.setPlotOptions(plotOptionsColumn);
series.setName("Rainfall");
series.setyAxis(1);
series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
series.setPlotOptions(plotOptionsSpline);
series.setName("Sea-Level Pressure");
series.setyAxis(2);
series.setData(1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7);
conf.addSeries(series);
series = new DataSeries();
plotOptionsSpline = new PlotOptionsSpline();
series.setPlotOptions(plotOptionsSpline);
series.setName("Temperature");
series.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
conf.addSeries(series);
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class Area method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.AREA);
final Configuration configuration = chart.getConfiguration();
configuration.setTitle("Historic and Estimated Worldwide Population Growth by Region");
configuration.setSubTitle("Source: Wikipedia.org");
XAxis xAxis = configuration.getxAxis();
xAxis.setCategories("1750", "1800", "1850", "1900", "1950", "1999", "2050");
xAxis.setTickmarkPlacement(TickmarkPlacement.ON);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle("Billions");
yAxis.getLabels().setFormatter("function () { return this.value / 1000;}");
configuration.getTooltip().setValueSuffix(" millions");
PlotOptionsArea plotOptionsArea = new PlotOptionsArea();
plotOptionsArea.setStacking(Stacking.NORMAL);
configuration.setPlotOptions(plotOptionsArea);
configuration.addSeries(new ListSeries("Asia", 502, 635, 809, 947, 1402, 3634, 5268));
configuration.addSeries(new ListSeries("Africa", 106, 107, 111, 133, 221, 767, 1766));
configuration.addSeries(new ListSeries("Europe", 163, 203, 276, 408, 547, 729, 628));
configuration.addSeries(new ListSeries("America", 18, 31, 54, 156, 339, 818, 1201));
configuration.addSeries(new ListSeries("Oceania", 2, 2, 2, 6, 13, 30, 46));
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project DoodleVerse by davidemarcoli.
the class StatisticsView method setupPage.
public void setupPage() {
Chart moneyBoxplot = new Chart(ChartType.BOXPLOT);
// Modify the default configuration a bit
Configuration conf = moneyBoxplot.getConfiguration();
conf.setTitle("Money Boxplot");
conf.getLegend().setEnabled(false);
// Set median line color and thickness
PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
plotOptions.setWhiskerLength("80%");
plotOptions.setAllowPointSelect(true);
conf.setPlotOptions(plotOptions);
DataSeries series = new DataSeries();
PersonStatAnalysis analysis = new PersonStatAnalysis(personRepository.findAll());
series.add(new BoxPlotItem(analysis.low(), analysis.quartile(25), analysis.median(), analysis.quartile(75), analysis.high()));
conf.setSeries(series);
add(moneyBoxplot);
setSizeFull();
}
use of com.vaadin.flow.component.charts.Chart in project komunumo-server by komunumo.
the class AnalyticsBoard method populateCharts.
private void populateCharts(@NotNull final Year year) {
// Top row widgets
final var registrations = databaseService.countAttendeesByYear(year, NoShows.INCLUDE);
final var events = databaseService.countEventsByYear(year);
final var noShows = databaseService.countAttendeesByYear(year, NoShows.ONLY);
numberOfRegistrations.setText(FormatterUtil.formatNumber(registrations));
numberOfEvents.setText(FormatterUtil.formatNumber(events));
noShowRate.setText(FormatterUtil.formatNumber(registrations == 0 ? 0 : noShows * 100L / registrations) + "%");
final var locationColorMap = databaseService.getAllLocationColors();
// First chart
final var configuration = monthlyVisitors.getConfiguration();
databaseService.calculateMonthlyVisitorsByYear(year).stream().map(data -> {
final var series = new ListSeries(data.location(), data.january(), data.february(), data.march(), data.april(), data.may(), data.june(), data.july(), data.august(), data.september(), data.october(), data.november(), data.december());
final var colorCode = locationColorMap.get(data.location());
if (colorCode != null) {
final var options = new PlotOptionsColumn();
options.setColor(new SolidColor(colorCode));
series.setPlotOptions(options);
}
return series;
}).forEach(configuration::addSeries);
final var x = new XAxis();
x.setCrosshair(new Crosshair());
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
configuration.addxAxis(x);
final var y = new YAxis();
y.setMin(0);
y.setTitle("");
configuration.addyAxis(y);
final var tooltip = new Tooltip();
tooltip.setShared(true);
configuration.setTooltip(tooltip);
}
Aggregations