jgv115
jgv115

Reputation: 509

charts_flutter - How to set the interval on x axis ticks

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:

enter image description here

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.

Upvotes: 5

Views: 9396

Answers (1)

Parth Dave
Parth Dave

Reputation: 2126

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

Upvotes: 11

Related Questions