'how can i implement real-time fl_chart flutter?
This is fl_chart i want to implement realtime graph for eg., heart rate against time.
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('#')
.orderBy("ad")
.limitToLast(5)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return LineChart(
mainData(snapshot.data),
);
}
this the real time data where the data being constructed
LineChartData mainData(QuerySnapshot graphData) {
var liveGraphData;
liveGraphData = graphData.docs
.map((documentSnapshot) => Gadget.fromMap(documentSnapshot.data()))
.toList();
List<FlSpot> gatherGraphData() {
List<FlSpot> graphPoints = [];
for (int i = 0; i < liveGraphData.length; i++) {
graphPoints.add(
FlSpot((liveGraphData[i].ts).toDouble(), liveGraphData[i].yadc));
}
print(graphPoints.length);
return graphPoints;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
