Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

TimeSeriesChart domainAxis ViewPort not being accepted #134

Open
lordgreg opened this issue Sep 19, 2018 · 4 comments
Open

TimeSeriesChart domainAxis ViewPort not being accepted #134

lordgreg opened this issue Sep 19, 2018 · 4 comments

Comments

@lordgreg
Copy link

Example:

new charts.TimeSeriesChart(
        seriesList,
        domainAxis: new charts.DateTimeAxisSpec(
            viewport: charts.DateTimeExtents(
              start: DateTime.now(),
              end: DateTime.now()..add(new Duration(days: 3))
            ),
...

The X axis won't show the 3 days but the min (being minimum element from seriesList) and max (being the maximum element from seriesList - in my example, this is set for today's date 18:00).

Diagram is not stretched on 3 days.

@keidaroo
Copy link

Having a same issue here.
Even I tried selecting the viewport like the code above, it doesn't affect anything.

      domainAxis: new charts.DateTimeAxisSpec(
          viewport: new charts.DateTimeExtents(start:new DateTime(2017,9,19,0,0),end:new DateTime(2017,9,19,4,0))),
final data = [
      new TimeSeriesSales(new DateTime(2017, 9, 19, 0, 0), 5),
      new TimeSeriesSales(new DateTime(2017, 9, 19, 2, 50), 25),
      new TimeSeriesSales(new DateTime(2017, 9, 19, 3, 49), 100),
      new TimeSeriesSales(new DateTime(2017, 9, 19, 7, 9), 75),
    ];

screen shot 2019-01-27 at 2 34 16

@AndreaMiotto
Copy link

any news on this issue?

@matthewlloyd
Copy link

This is because of the autoViewport setting in the Axis class (charts_common/lib/src/chart/cartesian/axis/axis.dart). You have to set axis.autoViewport = false in the DateTimeAxisSpec.configure method. This also allows the viewport to be changed dynamically.

@bjornwilliam
Copy link

bjornwilliam commented Sep 19, 2019

Posting a reply from a similar issue (#287) :
(add the viewport argument to his proposed workaround class). This workaround makes the datetime
viewport work as expected.

This is because of the autoViewport setting in the Axis class (charts_common/lib/src/chart/cartesian/axis/axis.dart). You have to set axis.autoViewport = false in the DateTimeAxisSpec.configure method. This also allows the PanAndZoomBehavior to operate correctly.

You're right. So, to fix that, the workaround is to create a class which extends DateTimeAxisSpec of charts_flutter and override the configure method like that :

class DateTimeAxisSpecWorkaround extends DateTimeAxisSpec {

const DateTimeAxisSpecWorkaround ({
RenderSpec renderSpec,
DateTimeTickProviderSpec tickProviderSpec,
DateTimeTickFormatterSpec tickFormatterSpec,
bool showAxisLine,
}) : super(
renderSpec: renderSpec,
tickProviderSpec: tickProviderSpec,
tickFormatterSpec: tickFormatterSpec,
showAxisLine: showAxisLine);

@OverRide
configure(Axis axis, ChartContext context,
GraphicsFactory graphicsFactory) {
super.configure(axis, context, graphicsFactory);
axis.autoViewport = false;
}
}
Thank you so much. You saved my day !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants