I want to draw a line chart in flutter. I follow this tutorial, it works fine if the date and month is different.
But why if it only has one date and one point, the
With just one point the X axis has no scale, so it zooms in showing the single date in as much resolution as it can - in this case down to the nearest minute. That's midnight ("12AM") on the twelfth of March. To force a fixed scale use a StaticDateTimeTickProviderSpec
. For example:
return Scaffold(
appBar: AppBar(
title: Text('Graph'),
),
body: Container(
height: 500,
width: double.infinity,
child: charts.TimeSeriesChart(
_createSampleData(seriesList),
domainAxis: charts.DateTimeAxisSpec(
tickProviderSpec: charts.StaticDateTimeTickProviderSpec(
<charts.TickSpec<DateTime>>[
charts.TickSpec<DateTime>(DateTime(2020, 3, 1)),
charts.TickSpec<DateTime>(DateTime(2020, 3, 6)),
charts.TickSpec<DateTime>(DateTime(2020, 3, 11)),
charts.TickSpec<DateTime>(DateTime(2020, 3, 16)),
charts.TickSpec<DateTime>(DateTime(2020, 3, 21)),
charts.TickSpec<DateTime>(DateTime(2020, 3, 26)),
charts.TickSpec<DateTime>(DateTime(2020, 4, 1)),
],
),
tickFormatterSpec: charts.AutoDateTimeTickFormatterSpec(
day: charts.TimeFormatterSpec(
format: 'dd MMM',
transitionFormat: 'dd MMM',
),
),
),
animate: false,
behaviors: [
charts.SlidingViewport(),
charts.PanAndZoomBehavior(),
],
dateTimeFactory: const charts.LocalDateTimeFactory(),
defaultRenderer: charts.LineRendererConfig(
includePoints: true,
),
),
),
);