fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

axisNameWidget not centered based on axis/chart height

Open valentinkatic opened this issue 1 year ago • 2 comments

I am using a simple bar chart with a leftTitles configuration that includes an axisNameWidget.

The title configuration is as follows:

AxisTitles(
  axisNameWidget: Text(
      axisTitle,
      style: axisTitleTextStyle,
  ),
  ...
)

Expected Behavior: I expected the axisNameWidget (the axis name) to be centered relative to the axis/chart height.

Actual Behavior: The axisNameWidget is centered based on the full chart height, which includes:

  • The chart itself
  • Bottom side titles
  • Bottom axis name

As a result, the axis title (as shown in the screenshot) is positioned between the values 20-40, whereas the expected position is between 40-60 (center of the chart).

EDIT: The same issue occurs on the other axis where the title "Months" is positioned between March and April. However, since the center label is April, the expected title position should be directly below April.

Screenshot: Screenshot_20250113_151024

valentinkatic avatar Jan 13 '25 14:01 valentinkatic

I just encountered this too, and was hoping that there was a workaround somewhere.

ksdhans avatar Sep 03 '25 06:09 ksdhans

You can use a Transform.translate() wrapper to offset by half the bottom reserved area. For example:

axisNameWidget: Transform.translate(
  offset: const Offset(bottomReserved / 2, 0),
  child: Text( 
    "Axis Title",
  ),
),`

Of course, that's going to look bad as soon as they fix this bug. But, it works for now.

ksdhans avatar Sep 03 '25 07:09 ksdhans