flutter - Flutter:Syncfusion图表为y轴提供上限
问题描述
我有一个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% 之类的东西。
如果有更好的方法来显示百分比,也将不胜感激。
解决方案
我们查看了问题和代码,可以通知您轴范围由数据源值确定。如果您不希望显示大于 100 的值,请使用轴中的最大值属性并手动自定义范围。有关详细信息,请参阅帮助文档。您还可以使用numberFormat属性来反映百分比值,如下例所示。
对于 100% 堆叠图表,请参阅支持文档,它将给定数据转换为 100%。
推荐阅读
- rest - 使用 NGINX 通过 Keycloak Oauth2 提供程序保护我的 RESTful 服务
- javascript - 在 React Native 中使用多个复选框处理状态
- powerapps - 尝试切换元素的可见性时如何在 PowerApps 中正确使用 If 语句?
- java - Java8 UnitTesting CompletableFuture 异常
- angular - 将页面状态作为参数保存到当前路由
- python - 尝试将多处理应用于将 xml 处理为 csv 的函数
- alloy - 合金翻译限制:关系的复杂性
- javascript - 放置在 JavaScript 文件中名为 HTML 的变量中添加的标签中时,onClick 不起作用
- vue.js - Vue输入中的特殊字符问题
- spring - 如何在 Legecy(Spring web-mvc)代码中发现我的服务(Spring Boot 应用程序)