Different types of charts

This commit is contained in:
Pit Friedrich
2026-07-06 07:33:15 +02:00
parent 9ffba461fe
commit af79286cb0
9 changed files with 136 additions and 44 deletions
@@ -1,6 +1,8 @@
package com.example.views;
import com.example.components.ApexChart;
import com.example.components.BarChart;
import com.example.components.LineChart;
import com.example.components.PieChart;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
@@ -11,18 +13,38 @@ import java.util.List;
public class DashboardView extends VerticalLayout {
public DashboardView() {
ApexChart chart = new ApexChart(ApexChart.ChartType.LINE);
chart.setWidthFull();
chart.setHeight("400px");
chart.setData("Umsatz 2026",
LineChart lineChart = new LineChart();
lineChart.setWidthFull();
lineChart.setHeight("400px");
lineChart.setData("Umsatz 2026",
List.of(30.0, 40.0, 35.0, 50.0, 49.0, 60.0),
List.of("Jan", "Feb", "Mär", "Apr", "Mai", "Jun"));
chart.addPointClickListener(e -> {
lineChart.addPointClickListener(e -> {
Notification.show("Serie %d, Punkt %d"
.formatted(e.getSeriesIndex(), e.getDataPointIndex()));
});
add(chart);
BarChart barChart = new BarChart();
barChart.setWidthFull();
barChart.setHeight("400px");
barChart.setData("Umsatz 2026",
List.of(30.0, 40.0, 35.0, 50.0, 49.0, 60.0),
List.of("Jan", "Feb", "Mär", "Apr", "Mai", "Jun"));
barChart.addPointClickListener(e -> {
Notification.show("Serie %d, Punkt %d"
.formatted(e.getSeriesIndex(), e.getDataPointIndex()));
});
PieChart pieChart = new PieChart();
pieChart.setWidthFull();
pieChart.setHeight("400px");
pieChart.setData(
List.of(30.0, 40.0, 35.0, 50.0),
List.of("Nord", "Süd", "Ost", "West"));
pieChart.addPointClickListener(e -> {
Notification.show("Slice %d".formatted(e.getDataPointIndex()));
});
add(lineChart, barChart, pieChart);
}
}