Swift Charts: Fixed size for Y axis labels, for perfect alignment with multiple vertically aligned charts
11:03 22 Feb 2023

I have multiple charts stacked vertically in a view. All charts have a common X axis made of Date (same range for all charts) The Y axis differ but are all Double values

Problem: the Y axis label differ in size (some are in the 4 digits format, some in the 2 digits) resulting in charts x values not being perfectly aligned with each other.

How can I set a fixed spaced for the Y axis labels?

What I tried but did not work

.chartYAxis {
    AxisMarks() { date in
        AxisGridLine()
        AxisValueLabel(offsetsMarks: false, horizontalSpacing: 50) // Tried offsetsMarks to both false & true, tried different values for horizontalSpacing but it seems to add up to the size of the label itself, resulting in a different behavior
    }
}

Here is the image showing the charts not aligned due to the labels non vertically-aligned charts

swift swiftui charts