import 'package:flutter/cupertino.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; class StackedColumnChart extends StatelessWidget { final List lowerValues; final List 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: [ StackedColumnSeries( dataSource: _getLowerChartData(), xValueMapper: (SalesData sales, _) => sales.year, yValueMapper: (SalesData sales, _) => sales.value, color: CupertinoColors.systemRed.highContrastColor, ), StackedColumnSeries( dataSource: _getUpperChartData(), xValueMapper: (SalesData sales, _) => sales.year, yValueMapper: (SalesData sales, _) => sales.value, color: CupertinoColors.systemBlue.highContrastColor, ), ], ); } List _getLowerChartData() { List chartData = []; for (int i = 0; i < lowerValues.length; i++) { chartData.add(SalesData(i + 1, lowerValues[i])); } return chartData; } List _getUpperChartData() { List 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); }