我正在使用以下代码段绘制一些实时时间序列折线图:
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轴标签:
我想知道是否有人可以帮助我弄清楚如何制作它,以便在x轴上有许多均匀间隔的刻度。
谢谢
编辑:dataArray
是类型List<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...
此HistoryData
中有60个List
对象,每个date
中的每个HistoryData
值彼此相距2秒。
答案 0 :(得分:1)
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并检查输出