Initial commit

This commit is contained in:
Pit Friedrich
2026-07-05 17:06:59 +02:00
parent 0935b7a98a
commit 23b392a19b
11 changed files with 5144 additions and 0 deletions
@@ -0,0 +1,57 @@
package com.example.components;
import com.vaadin.flow.component.*;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.shared.Registration;
import tools.jackson.databind.json.JsonMapper;
import java.util.List;
import java.util.Map;
@Tag("apex-chart")
@NpmPackage(value = "apexcharts", version = "5.15.2")
@JsModule("./components/apex-chart.ts")
public class ApexChart extends Component implements HasSize {
private static final JsonMapper MAPPER = JsonMapper.builder().build();
public void setData(String seriesName, List<Double> values, List<String> categories) {
Map<String, Object> options = Map.of(
"chart", Map.of("type", "bar", "height", "100%"),
"series", List.of(Map.of("name", seriesName, "data", values)),
"xaxis", Map.of("categories", categories)
);
getElement().callJsFunction("renderChart", MAPPER.writeValueAsString(options));
}
@ClientCallable
private void onPointClick(int seriesIndex, int dataPointIndex) {
fireEvent(new PointClickEvent(this, true, seriesIndex, dataPointIndex));
}
public Registration addPointClickListener(ComponentEventListener<PointClickEvent> listener) {
return addListener(PointClickEvent.class, listener);
}
public static class PointClickEvent extends ComponentEvent<ApexChart> {
private final int seriesIndex;
private final int dataPointIndex;
PointClickEvent(ApexChart source, boolean fromClient, int seriesIndex, int dataPointIndex) {
super(source, fromClient);
this.seriesIndex = seriesIndex;
this.dataPointIndex = dataPointIndex;
}
public int getDataPointIndex() {
return dataPointIndex;
}
public int getSeriesIndex() {
return seriesIndex;
}
}
}
@@ -0,0 +1,28 @@
package com.example.views;
import com.example.components.ApexChart;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import java.util.List;
@Route("")
public class DashboardView extends VerticalLayout {
public DashboardView() {
ApexChart chart = new ApexChart();
chart.setWidthFull();
chart.setHeight("400px");
chart.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 -> {
Notification.show("Serie %d, Punkt %d"
.formatted(e.getSeriesIndex(), e.getDataPointIndex()));
});
add(chart);
}
}