Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

BarChart change bar label size, enable pan and pinch to zoom behavior #753

@piotrkovsy1331

Description

@piotrkovsy1331

Hey Im facing a problems with BarChart:

  1. How can i enable zooming on te chart ?
  2. How can i change bar labels size and display direction ?

Description of issues:

  1. I want to achieve having a barChart with panning and pinch to zoom behavior, Google didn't helped me very much i found that i can add
    behaviors: [ charts.PanBehavior(), charts.PanAndZoomBehavior(), ],.
    to the BarChart parameters but it didn't work. Any ideas ?

2.I have situations where i need to show more than 10 or 20 bars on one chart. When number of charts is small everything looks fine. Labels are shown properly. But when number of bars increases labels changes it display direction from horizontal to vertical. My goal is to block that behavior and force labels to stay horizontal and scale to the Bar's width. You can see it on screenshots below. Does anybody has idea how to solve it ?

Zrzut ekranu 2022-03-28 o 13 44 13
Zrzut ekranu 2022-03-28 o 13 44 27

`import 'package:charts_flutter/flutter.dart' as charts;

import '../models/drive_style_series.dart';
import 'package:flutter/material.dart';

class DriveSummaryChart extends StatelessWidget {
const DriveSummaryChart({Key? key, required this.dataSeriesList})
: super(key: key);

final List dataSeriesList;

@OverRide
Widget build(BuildContext context) {
List<charts.Series<DriveStyleSeries, String>> series = [
charts.Series(
id: 'km',
data: dataSeriesList,
labelAccessorFn: (DriveStyleSeries series, _) =>
series.distance.toDouble().toStringAsFixed(1),
domainFn: (DriveStyleSeries series, _) => series.date,
measureFn: (DriveStyleSeries series, _) => series.distance,
colorFn: (DriveStyleSeries series, _) => charts.ColorUtil.fromDartColor(
Colors.greenAccent),
),
];
return SizedBox(
height: 300,
child: charts.BarChart(
series,
animate: true,
animationDuration: const Duration(milliseconds: 200),
barRendererDecorator: charts.BarLabelDecorator(
labelPosition: charts.BarLabelPosition.outside,
labelAnchor: charts.BarLabelAnchor.middle,
labelPadding: 5,
outsideLabelStyleSpec: charts.TextStyleSpec(
color: charts.ColorUtil.fromDartColor(Colors.black)),
),
primaryMeasureAxis:
const charts.NumericAxisSpec(renderSpec: charts.NoneRenderSpec()),
domainAxis: const charts.OrdinalAxisSpec(
showAxisLine: false, renderSpec: charts.NoneRenderSpec()),
behaviors: [
charts.PanBehavior(),
charts.PanAndZoomBehavior(),
],
layoutConfig: charts.LayoutConfig(
bottomMarginSpec: charts.MarginSpec.fixedPixel(0),
leftMarginSpec: charts.MarginSpec.fixedPixel(0),
rightMarginSpec: charts.MarginSpec.fixedPixel(0),
topMarginSpec: charts.MarginSpec.fixedPixel(20),
),
),
);
}
}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions