Search code examples
flutterlinechartsyncfusion

Flutter: Show "No Data" message in Syncfusion CartesianChart


I am using the syncfusion library for Flutter and I can build a line chart when I have data. However, if the list is empty, it simply draws axes and that is all. Even though this is expected, I want to write a "No Data" message in the center of the chart.

Here is my chart widget:

             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}%',
                  labelStyle: TextStyle(fontWeight: FontWeight.bold)
                ),
              ),

Is there any way to show such message?


Solution

  • We have looked through the question and like to tell you that we can meet the requirement by using the chart's annotations property. We can position the Text Widget with ‘No Data' if the data source is empty, otherwise, we can allocate the empty container to the annotations. Using these annotations, we can place the necessary widget in the required position in the map, and for more detail, see the support document and we have attached the sample as a reference.

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