I'm plotting a few live time series line charts using the following snippet:
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);
}
The data displays fine but I've noticed that there is only one x axis labels:
I was wondering if anyone could help me figure out how to make it so there are many evenly spaced ticks on the x axis.
Thanks
EDIT: dataArray
is a variable of type List<HistoryData>
This is the print:
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...
There are 60 HistoryData
objects in this List
and each date
value in each HistoryData
is 2 seconds apart from each other.
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,
),
),
this line sets how much inrement you want to show ticks on domain or bottom axis
tickProviderSpec: charts.DayTickProviderSpec(increments: [1]),
change increments to 2 and 3 and check the output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With