Flutter:Syncfusion Chart 给出 y 轴的上限

问题描述 投票:0回答:3

我有一个

SfCartesianChart
显示从 0 到 100 的值列表的折线图,即百分比。但是,当有一个数据点时,例如99%,y轴的上限似乎是120%,这没有任何意义。

这是我的图表代码

       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: records,
                xValueMapper: (MoodRecord record, _) => record.date,
                yValueMapper: (MoodRecord record, _) => record.mood.toInt(),
                dataLabelSettings: DataLabelSettings(isVisible: false),
                enableTooltip: true,
                animationDuration: 2000,
                markerSettings: MarkerSettings(
                    isVisible: true,
                    shape: DataMarkerType.circle,
                    color: kPrimaryColor
                )
              )
          ],
          primaryXAxis: CategoryAxis(
            labelPlacement: LabelPlacement.onTicks,
            labelStyle: TextStyle(fontWeight: FontWeight.bold)
          ),
          primaryYAxis: NumericAxis(
            labelFormat: '{value}%',
            labelStyle: TextStyle(fontWeight: FontWeight.bold)
          ),
        ),

有什么方法可以定义 y 轴的上限吗?我不希望我的图表在 y 轴上显示 120% 之类的东西。

如果有更好的显示百分比的方法,也将不胜感激

flutter linechart syncfusion
3个回答
0
投票
primaryYAxis: NumericAxis(maximum: 3.3)

-1
投票

我们查看了问题和代码,可以通知您轴范围由数据源值确定。如果您不想显示超过 100 的值,请在轴中使用 maximum 属性并手动自定义范围。有关更多详细信息,请参阅帮助文档。您也可以使用 numberFormat 属性来反映百分比值,如下例所示。

https://www.syncfusion.com/kb/11519/how-to-apply-the-currency-format-to-the-axis-labels-sfcartesianchart

对于 100% 堆叠图表,请参阅 支持文档,它将给定数据转换为 100%。


-1
投票
SfCartesianChart(
    primaryXAxis: CategoryAxis(labelStyle: const TextStyle(
        color: Colors.white,
        fontFamily: 'Roboto',
        fontSize: 10,
    )),

    primaryYAxis: NumericAxis(
        **minimum: 0, maximum: 100, interval: 25,**
        labelFormat: '{value}%',
        labelStyle: const TextStyle(
        color: Colors.white,
        fontFamily: 'Roboto',
        fontSize: 10,
    )),
© www.soinside.com 2019 - 2024. All rights reserved.