2
votes

I am trying to familiarize with charts in Flutter, using github.com/google/charts package.

I want to make a chart (bar, line, scatter or any other.. this, for example) where I can zoom and pan not only the x-axis, but also the vertical y-axis (abscissa).

The zoom in x-axis is working adding the behavior behaviors: [new charts.PanAndZoomBehavior(),] :

@override
Widget build(BuildContext context) {
    return new charts.BarChart(
      seriesList,
      animate: animate,
      behaviors: [new charts.PanAndZoomBehavior(),
      ],
      domainAxis: new charts.OrdinalAxisSpec(
          viewport: new charts.OrdinalViewport('2018', 4)),
    );
  }

the x-axis zoom is not centered, as asked in this question, but it's ok to me.

A first step would be disable the auto-fit of the vertical axis is adjusting the range between 0 and the max value of the data that appear in that moment in the chart.

Any idea how to enable zoom gesture on the y-axis or at least disable the auto-fit of y-axis (fix the range of y-axis)?

1

1 Answers

0
votes

It is quite similar to what you did in domainAxis.
You could just add an axisSpec to the primaryMeasureAxis (y-axis). like this,

primaryMeasureAxis: charts.NumericAxisSpec(
      viewport: charts.NumericExtents(4, 8)),

But this doesn't work properly in bar charts.
As of my experience, the bar chart will go below the x-axis. It hasn't be fixed yet.
It works well with line chart though.