Flutter:在 Syncfusion CartesianChart 中显示“无数据”消息

问题描述

我正在为 Flutter 使用 syncfusion 库,当我有数据时,我可以构建折线图。但是,如果列表为空,则它只是绘制轴,仅此而已。即使这是意料之中的,我还是想在图表的中心写一条“无数据”消息。

这是我的图表小部件:

             SfCartesianChart(
                margin: EdgeInsets.all(0),borderWidth: 0,plotAreaBorderWidth: 0,title: ChartTitle(text: 'Mood Tracks',textStyle: TextStyle(fontWeight: FontWeight.bold)),tooltipBehavior: _tooltipBehavior,series: <ChartSeries>[
                  Lineseries<MoodRecord,dynamic>(
                      name: 'Moods',color: Colors.green[400],dataSource: [],xValueMapper: (MoodRecord record,_) => record.date,yValueMapper: (MoodRecord record,_) => record.mood.toInt(),dataLabelSettings: DataLabelSettings(isVisible: true),enabletooltip: true)
                ],primaryXAxis: CategoryAxis(
                  labelPlacement: LabelPlacement.onTicks,labelStyle: TextStyle(fontWeight: FontWeight.bold)
                ),primaryYAxis: NumericAxis(
                  labelFormat: '{value}%',),

有没有办法显示这样的消息?

解决方法

来自 Syncfusion 的问候。我们已经浏览了问题并想告诉您,我们可以通过使用图表的 annotations 属性来满足要求。如果数据源为空,我们可以使用“无数据”定位文本小部件,否则,我们可以将空容器分配给注释。使用这些注释,我们可以将必要的小部件放置在地图中所需的位置,更多详细信息,请参见support document,我们已附上示例作为参考,如果您需要任何其他帮助,请联系我们.

示例:https://www.syncfusion.com/downloads/support/directtrac/326033/ze/I326033_no_data_text48946494

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...