gpt4 book ai didi

dart - charts_flutter - 如何设置 x 轴刻度的间隔

转载 作者:IT王子 更新时间:2023-10-29 06:43:39 33 4
gpt4 key购买 nike

我正在使用以下代码片段绘制一些实时时间序列折线图:

  new SizedBox(
height: MediaQuery.of(context).size.height / 4,
child: new charts.TimeSeriesChart([
new charts.Series<HistoryData, DateTime>(
id: 'test',
colorFn: (_, __) => colourArray[dataArrayName],
data: dataArray,
domainFn: (HistoryData sales, _) => sales.date,
measureFn: (HistoryData sales, _) => sales.historyValue)
],
animate: true,
dateTimeFactory: const charts.LocalDateTimeFactory()),
)

class HistoryData {
final DateTime date;
final double historyValue;

HistoryData(this.date, this.historyValue);
}

数据显示正常,但我注意到只有一个 x 轴标签:

enter image description here

我想知道是否有人可以帮我弄清楚如何制作它以便在 x 轴上有许多均匀间隔的刻度。

谢谢

编辑:dataArrayList<HistoryData> 类型的变量

这是打印品:

I/flutter (19864): [Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryData', Instance of 'HistoryDat...

有 60 个 HistoryDataList 中的对象每个 date每个值 HistoryData彼此相隔2秒。

最佳答案

charts.TimeSeriesChart(
_createSampleData(),
animate: true,
domainAxis: new charts.DateTimeAxisSpec(
tickProviderSpec: charts.DayTickProviderSpec(increments: [1]),
tickFormatterSpec: new charts.AutoDateTimeTickFormatterSpec(
day: new charts.TimeFormatterSpec(
format: 'EEE', transitionFormat: 'EEE', noonFormat: 'EEE'),
),
showAxisLine: false,
),
),

此行设置您希望在域或底轴上显示多少刻度

tickProviderSpec: charts.DayTickProviderSpec(increments: [1]),

将增量更改为 2 和 3 并检查输出

关于dart - charts_flutter - 如何设置 x 轴刻度的间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52885370/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com