Skip to content

Conversation

artshooter
Copy link

@artshooter artshooter commented Oct 16, 2025

Fixed incorrect bar chart color display when bar data values are small with large border radius set.

Fixes #1757

Root Cause

  1. The bar's main body (background) has a default background color
  2. Since the bar body's height cannot be lower than the border radius, the rendered bar body may be taller
    than the actual rendered height of the bar stack items (rodStackItems)
  3. The rendering logic draws the bar body background first, then overlays the bar stack items. When the
    stack items' height is insufficient to cover the entire bar body, the default background color becomes
    visible

Solution

When the actual height of the bar stack is smaller than the minimum height required for the corner radius,
a scale factor is introduced to proportionally expand the rendered height of the bar stack items. This
ensures they fully cover the bar body's height while maintaining the proportional relationships among
stack items.

Changes

  • Modified drawBars method in lib/src/chart/bar_chart/bar_chart_painter.dart
  • Added scale factor calculation logic, applied only when necessary
  • Added unit tests to verify the fix

Testing

  • ✅ Added unit test covering small values with large border radius scenario
  • ✅ Verified scaled stack items have correct heights and proportions
  • ✅ All existing tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bar chart rod color is wrong with small value

1 participant