2024-05-06 17:28:10 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
|
|
|
|
2024-05-10 13:37:09 +02:00
|
|
|
// Widget für ein gestapeltes Säulendiagramm
|
2024-05-06 17:28:10 +02:00
|
|
|
class StackedColumnChart extends StatelessWidget {
|
|
|
|
final List<double> lowerValues;
|
|
|
|
final List<double> upperValues;
|
|
|
|
|
|
|
|
const StackedColumnChart({
|
|
|
|
super.key,
|
|
|
|
required this.lowerValues,
|
|
|
|
required this.upperValues,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SfCartesianChart(
|
|
|
|
primaryXAxis: const CategoryAxis(
|
|
|
|
title: AxisTitle(text: 'Jahr'),
|
|
|
|
),
|
|
|
|
primaryYAxis: const NumericAxis(
|
|
|
|
title: AxisTitle(text: 'Euro'),
|
|
|
|
),
|
|
|
|
series: <CartesianSeries>[
|
2024-05-10 13:37:09 +02:00
|
|
|
// Untere Teil der Säule
|
2024-05-06 17:28:10 +02:00
|
|
|
StackedColumnSeries<SalesData, int>(
|
|
|
|
dataSource: _getLowerChartData(),
|
|
|
|
xValueMapper: (SalesData sales, _) => sales.year,
|
|
|
|
yValueMapper: (SalesData sales, _) => sales.value,
|
|
|
|
color: CupertinoColors.systemRed.highContrastColor,
|
|
|
|
),
|
2024-05-10 13:37:09 +02:00
|
|
|
// Obere Teil der Säule
|
2024-05-06 17:28:10 +02:00
|
|
|
StackedColumnSeries<SalesData, int>(
|
|
|
|
dataSource: _getUpperChartData(),
|
|
|
|
xValueMapper: (SalesData sales, _) => sales.year,
|
|
|
|
yValueMapper: (SalesData sales, _) => sales.value,
|
|
|
|
color: CupertinoColors.systemBlue.highContrastColor,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-10 13:37:09 +02:00
|
|
|
// Methode zum Erstellen der Daten für den unteren Teil der Säule (Investiertes Geld)
|
2024-05-06 17:28:10 +02:00
|
|
|
List<SalesData> _getLowerChartData() {
|
|
|
|
List<SalesData> chartData = [];
|
|
|
|
for (int i = 0; i < lowerValues.length; i++) {
|
|
|
|
chartData.add(SalesData(i + 1, lowerValues[i]));
|
|
|
|
}
|
|
|
|
return chartData;
|
|
|
|
}
|
2024-05-10 13:37:09 +02:00
|
|
|
// Methode zum Erstellen der Daten für den oberen Teil der Säule (Investiertes Geld mit Zinsen)
|
2024-05-06 17:28:10 +02:00
|
|
|
List<SalesData> _getUpperChartData() {
|
|
|
|
List<SalesData> chartData = [];
|
|
|
|
for (int i = 0; i < upperValues.length; i++) {
|
|
|
|
chartData.add(SalesData(i + 1, upperValues[i]));
|
|
|
|
}
|
|
|
|
return chartData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SalesData {
|
|
|
|
final int year;
|
|
|
|
final double value;
|
|
|
|
|
|
|
|
SalesData(this.year, this.value);
|
|
|
|
}
|