widget for line graph
parent
d9272bdfb2
commit
b23f9ccdc1
|
@ -0,0 +1,39 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:smoke_cess_app/providers/settings_provider.dart';
|
||||||
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||||
|
|
||||||
|
class LineChart<T> extends StatelessWidget {
|
||||||
|
final List<T> dataSource;
|
||||||
|
final DateTime? Function(T, int) xValueMapper;
|
||||||
|
final num? Function(T, int) yValueMapper;
|
||||||
|
const LineChart(
|
||||||
|
{super.key,
|
||||||
|
required this.dataSource,
|
||||||
|
required this.xValueMapper,
|
||||||
|
required this.yValueMapper});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
|
||||||
|
|
||||||
|
return SfCartesianChart(
|
||||||
|
primaryXAxis: DateTimeAxis(
|
||||||
|
minimum: settingsProvider.settings?.startedAt,
|
||||||
|
maximum: settingsProvider.settings?.startedAt
|
||||||
|
.add(const Duration(days: 7 * 6)),
|
||||||
|
interval: 7,
|
||||||
|
dateFormat: DateFormat.Md('de'),
|
||||||
|
),
|
||||||
|
primaryYAxis:
|
||||||
|
NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20),
|
||||||
|
series: <ChartSeries>[
|
||||||
|
LineSeries<T, DateTime>(
|
||||||
|
dataSource: dataSource,
|
||||||
|
xValueMapper: xValueMapper,
|
||||||
|
yValueMapper: yValueMapper),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue