Swift Chart RuleMark annotation not respecting overflow resolution when using chartScrollableAxis

I'm currently in the process on making a horizontally scrollable bar chart with selection. Upon selection, I want to show an annotation attached to a RuleMark. I want to be able to show this annotation above the chart plot area since it is large and will likely cover many bars.

I'm using the overflowResolution option on the annotation with the y set to disabled; however, this does not do anything and the annotation seems pushed up inside the plot area rather than overlapping with the plot area itself. If I comment out the chartScrollableAxis modifier than the overflow resolution works as expected.

Replies

Having a similar issue. The annotation and horizontal scrolling don't work together. Enabling scrolling results in the annotation not showing up anymore.

Same issue here, trying to reproduce the example used in the WWDC 23 Presentation "Explore Pit Charts and Interactivity in SwiftCharts" and the annotation doesn't appear. I worked around that issue by setting: y: .fit(to: .chart) in the init of the overflowResolution, like:

 .annotation(position: .top, spacing: 0, overflowResolution: .init(x: .fit(to: .chart), y: .fit(to: .chart)))

Probably a SwiftUI bug given this API is only a few months old.

Thanks @Geneva0 , solved it using this

 .annotation(position: .top, spacing: 0, overflowResolution: .init(x: .fit(to: .chart), y: .fit(to: .chart)))