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.

How to center label in top of barchart? #804

@BigGitWorld

Description

@BigGitWorld

Hi
I wan to show y-axis values as label on top-center of barcharts, but the lables (values provided by the labelAccessorFn ) are shown in top-left side.
why?

//barchart:
charts.BarChart(
        data(statistics),
        animate: true,
        barRendererDecorator: charts.BarLabelDecorator(
           insideLabelStyleSpec: charts.TextStyleSpec(color: charts.ColorUtil.fromDartColor(Colors.white)),
           outsideLabelStyleSpec: charts.TextStyleSpec(color: charts.ColorUtil.fromDartColor(Colors.white)),
        ),
        domainAxis: const charts.OrdinalAxisSpec(
          renderSpec: charts.SmallTickRendererSpec(
            labelRotation: 45,
            labelStyle: charts.TextStyleSpec(
              fontSize: 18,
              color: charts.MaterialPalette.white,
            ),
            lineStyle: charts.LineStyleSpec(
              color: charts.MaterialPalette.white,
            ),
          ),
        ),
      ),


//data:
List<charts.Series<BarChartPoint, String>> data(var statistics) {
    final data = [
      for (var item in statistics.details)
        BarChartPoint(
            label: item.name, value: item.count, color: Colors.red),
    ];
    return [
      charts.Series<BarChartPoint, String>(
        id: 'barchart-id',
        colorFn: (BarChartPoint point, _) =>
            charts.ColorUtil.fromDartColor(point.color ?? Colors.white),
        domainFn: (BarChartPoint point, _) => point.label,
        measureFn: (BarChartPoint point, _) => point.value,
        data: data,
        //strokeWidthPxFn: (BarChartPoint point, _) => 64,
        labelAccessorFn: (BarChartPoint point, _) => '${point.value}', //this is not top-center (it is top-left). why?
      )
    ];
  }

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