From 3ccb5a42d412f63a2e74eab1464bd8c4a11d0795 Mon Sep 17 00:00:00 2001 From: TAJAOUART Mounir Date: Fri, 10 Feb 2023 10:14:01 +0100 Subject: [PATCH] delete data that is no longer displayed on the graph after exceeding y axis --- lib/src/live_chart.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/live_chart.dart b/lib/src/live_chart.dart index f8691a0..a143706 100644 --- a/lib/src/live_chart.dart +++ b/lib/src/live_chart.dart @@ -47,6 +47,8 @@ class RealTimeGraphState extends State List> _data = []; Timer? timer; + double canvasWidth = 1000; + @override void initState() { super.initState(); @@ -56,7 +58,8 @@ class RealTimeGraphState extends State // Start a periodic timer to update the data for visualization timer = Timer.periodic(widget.updateDelay, (_) { - //_data.removeWhere((element) => element.y > 100); + // delete data that is no longer displayed on the graph. + _data.removeWhere((element) => element.x < canvasWidth * -1.5); // Clone the data to avoid modifying the original list while iterating List> data = _data.map((e) => e).toList(); @@ -113,6 +116,8 @@ class RealTimeGraphState extends State return const SizedBox.shrink(); } + canvasWidth = constraints.maxWidth; + return SizedBox( key: Key( '${constraints.maxWidth}${constraints.maxHeight}'),