Can't get Charts BarMark to resize with window

I have a Swift Charts bar chart that looks great when there is a narrow gap between vertical bars but not so good when gaps either get large or go away altogether. Have been trying to figure out how to make bars resize with window so that narrow gaps are maintained. Seems like this should work:

                BarMark(
                x: .value("Year", barSegment.age),
                y: .value("PercentSuccess", barSegment.percentage),
                width: MarkDimension.inset(CGFloat(10.0))
            )

In practice, though, this just ends up producing fixed width bars. Have also tried:

                BarMark(
                x: .value("Year", barSegment.age),
                y: .value("PercentSuccess", barSegment.percentage),
                width: MarkDimension.ratio(CGFloat(0.9))
            )

But this doesn't show bars at all, regardless of what argument I give to ratio.

How do I get the effect that I want?

I think your best option is to use a GeometryReader and calculate the bar width based on the available space.

Something like this:

    let gapSize: CGFloat = 1

    GeometryReader { proxy in
        Chart(data) { barSegment in
            BarMark(
                x: .value("Year", barSegment.age),
                y: .value("PercentSuccess", barSegment.percentage),
                width: .fixed(proxy.size.width / CGFloat(data.count) - gapSize)
            )
        }
    }
Can't get Charts BarMark to resize with window
 
 
Q