Skip to content

[Bug] v2.10.4 — BarChart Shrinks After Refresh Due to xAxisLabels Spacer & Negative Values Not Rendering in ChartView #255

Description

@MayankBimbra

🐞 Summary

There are two issues introduced (or more visible) in version v2.10.4 of the Charts library:


1️⃣ Negative Values Not Rendering

Problem:
When passing negative values into BarChartDataPoint, the bars are not rendered at all. This used to work in previous versions.

Repro Example:

let barDataPoints = [
    BarChartDataPoint(value: -20, xAxisLabel: "Jan", description: "January", colour: .init(colour: .red)),
    BarChartDataPoint(value: -50, xAxisLabel: "Jan", description: "January", colour: .init(colour: .red)),
    BarChartDataPoint(value: 20, xAxisLabel: "Jan", description: "January", colour: .init(colour: .red)),
    BarChartDataPoint(value: 100, xAxisLabel: "Feb", description: "February", colour: .init(colour: .green)),
    BarChartDataPoint(value: 150, xAxisLabel: "Feb", description: "February", colour: .init(colour: .green))
]

Expected:
Negative bars should appear below the baseline.

Actual:
Negative bars are completely missing.


2️⃣ Chart Shrinks After Refresh Due to Spacer() in getXAxisLabels()

Problem:
When chart data is refreshed (e.g., via .onAppear or navigating back), and .xAxisLabels(chartData:) is used, the chart height shrinks significantly—only occupying half or less of the defined height.

Root Cause:
Inside the getXAxisLabels() implementation, the following Spacer() causes the layout to behave inconsistently on refresh:

VStack {
    RotatedText(chartData: self, label: data.wrappedXAxisLabel, rotation: angle)
    Spacer()  // ⚠️ Causes chart to shrink on refresh
}

Fix (Confirmed Locally):
Commenting out or removing this Spacer() resolves the issue, and the chart maintains its defined height.


📽️ Video

A screen recording has been attached to demonstrate the layout collapsing issue on refresh when .xAxisLabels is used.

(https://drive.google.com/file/d/1T3ewCrWVpwLu97SAnHmcIEQ4zH1KP36F/view?usp=sharing)

✅ Suggestions

  • ✅ Render negative values as bars below the x-axis.
  • ✅ Revisit layout behavior in getXAxisLabels() and avoid unnecessary Spacer() that causes dynamic height shrinkage.

Appreciate the great work on this library! Happy to help test any fixes if needed. 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions