One possibility is to make the x-axis dynamic.
@observable
int xMinValue = 0;
@action
void updateXMinValue(int newValue) {
xMinValue = newValue;
}
That way you can generate the bars in a specific range
for (int i = controller.xMinValue; i <= indexController; i++) {
rawBarGroups.add(makeGroupData(
x: i,
bar1: widget.chartDataSet[i].bar1));
}
Finally, you can change this range from a swipe movement in the graph component, one way to do this is using the GestureDetector.
GestureDetector(
onHorizontalDragEnd: (DragEndDetails details) {
if (details.primaryVelocity! > 0 && controller.xMinValue > 0) {
controller.updateXMinValue(controller.xMinValue - 1);
} else if (details.primaryVelocity! < 0 && widget.chartDataSet.first.index! > controller.xMinValue + 7) {
controller.updateXMinValue(controller.xMinValue + 1);
}
},
child: BarChart(
BarChartData( ...
In a graph with a large number of spots, this solution can become a usability problem as navigation tends to be a little slower by using the swipe gesture. In these cases I recommend using a solution closer to a zoom in the graph, you can find an example here: https://github.com/imaNNeo/fl_chart/issues/71#issuecomment-1414267612