这是 fl_chart 我想实现实时图表,例如,心率随时间变化。
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('#')
.orderBy("ad")
.limitToLast(5)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return LineChart(
mainData(snapshot.data),
);
}
这是实时数据 在哪里构建数据
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;
}