[英]Flutter Pie Chart with Expanded Widget
I'm trying to put a pie chart from chart_flutter in Expanded Widget but have error "incorrect use of parent widget" I tried to wrap the parent Column with a container and give it a fixed height and width, remove the list view Widget, wrap the chart with a container, but no luck Please need help with this, keeping in mind that I have in this screen a data table so after the table occupying the required space I need the chart take the rest.我正在尝试将来自 chart_flutter 的饼图放入 Expanded Widget 但出现错误“不正确使用父小部件”我试图用容器包装父列并为其提供固定的高度和宽度,删除列表视图小部件,换行带有容器的图表,但没有运气 请在这方面需要帮助,请记住,我在此屏幕中有一个数据表,因此在表格占据所需空间后,我需要图表采用 rest。 Thanks in advance.提前致谢。
here is a little example for what i have suggested for you using syncfusion_flutter_charts
and FireStore
:这是我使用syncfusion_flutter_charts
和FireStore
为您建议的一个小例子:
Widget build(BuildContext context) {
Future getElderlyId() async {
await FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser.uid)
.get()
.then((data) {
setState(() {
elderlyId = data.data()['elderlyId'];
});
});
}
return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('glucose')
.where('uid', isEqualTo: elderlyId)
.snapshots(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
// return Center(
// child: CircularProgressIndicator(),
// );
List<ChartData> chartData = [];
for (int index = 0;
index < snapshot.data.docs.length;
index++) {
DocumentSnapshot documentSnapshot = snapshot.data.docs[index];
chartData.add(ChartData.fromMap(documentSnapshot.data()));
}
return Container(
child: Column(
children: [
Text(
"رسم بياني لمستويات السكر خلال اسبوع",
style: textStyle2,
),
Directionality(
textDirection: TextDirection.ltr,
child: SfCartesianChart(
plotAreaBorderWidth: 0,
margin: EdgeInsets.all(10),
// primaryXAxis: CategoryAxis(
// maximumLabelWidth: 80,
// ),
primaryXAxis: DateTimeAxis(
// Interval type will be months
intervalType: DateTimeIntervalType.days,
interval: 1),
primaryYAxis: CategoryAxis(
maximumLabelWidth: 80,
),
enableAxisAnimation: true,
// borderColor: yellow,
series: <CartesianSeries<ChartData, dynamic>>[
ColumnSeries<ChartData, dynamic>(
color: yellow,
dataSource: chartData,
xAxisName: "days",
yAxisName: "values",
// color: yellow,
animationDuration: 20,
xValueMapper: (ChartData gelu, _) =>
gelu.xValue,
yValueMapper: (ChartData gelu, _) =>
gelu.yValue,
)
]),
),
],
),
);
} else {
return CircularProgressIndicator();
}
}));
}
}
class ChartData {
ChartData(this.xValue, this.yValue);
ChartData.fromMap(Map<String, dynamic> dataMap)
: xValue = dataMap['date'],
yValue = dataMap['glucose'];
Timestamp xValue;
double yValue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.