Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

charts_flutter - How to set the interval on x axis ticks

Tags:

flutter

dart

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.

like image 215
jgv115 Avatar asked Jan 02 '23 17:01

jgv115


1 Answers

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

like image 54
Parth Dave Avatar answered Jan 20 '23 01:01

Parth Dave