I've been working on migrating some graphics to Swift Charts for an app I work on. However I've been noticing strange behavior when it comes to VoiceOver. If I create a bar chart and use:
BarMark(x: .value("Month", x, unit: .month), y: ...)
While the chart looks fine, the voice over values seem to follow arbitrary values set for the bin. From what I can tell they are following the underlying bin values that Swift Charts uses to provide spacing between bars.
For instance, this simple example:
let monthlyRevenueData = [
(x: try! Date("2024-01-01T00:00:00Z", strategy: .iso8601), y: (income: 55000, revenue: 124000), id: UUID()),
(x: try! Date("2024-02-01T00:00:00Z", strategy: .iso8601), y: (income: 58000, revenue: 130000), id: UUID()),
(x: try! Date("2024-03-01T00:00:00Z", strategy: .iso8601), y: (income: 59000, revenue: 120000), id: UUID()),
]
struct ContentView: View {
var body: some View {
Chart(monthlyRevenueData, id: \.id) { (x, y, _) in
BarMark(x: .value("Month", x, unit: .month), y: .value("Income", y.income))
.foregroundStyle(.green)
BarMark(x: .value("Month", x, unit: .month), y: .value("Revenue", y.revenue))
}
}
}
#Preview {
ContentView()
}
Results in the Voice Over reading "January 14th 2024 at 12 AM to January 28th 2024 at 12am ..." despite the fact that the data should be for the entire month of Jan.
Is there any way to get VoiceOver to read the input data rather than relying on how the chart is formatted? Preferably without the need to remove all visual spacing between the bars.
Video link: https://drive.google.com/file/d/11mxCl3wR2HzoOaihOvci-vZk4zgG1d39/view?usp=drive_link