I"m try to display two sets of data on a SwiftUI Charts Bar Graph. I want to bars to display side-by-side (i.e. blue-green, blue-green for the sample image). However, what I'm getting is the two sets of bars displayed separately as shown in the image. What am I doing wrong?
Here's my code: The structure of the data isn't fixed, so it can change if necessary.
struct ContentView: View {
var body: some View {
let wheelDevelopmentArray = [
(chainring: "one", eff:[75, 69, 64, 60, 56, 53, 47, 43, 39, 36, 32]),
(chainring: "two", eff:[110, 101, 94, 88, 82, 77, 69, 63, 57, 53, 47])
]
Chart(wheelDevelopmentArray, id: \.chainring) { wheels in
ForEach(0..<wheels.eff.count, id: \.self) { i in
BarMark(
x: .value("gear", wheels.chainring),
y: .value("size", wheels.eff[i]),
width: 20
)
.foregroundStyle(by: .value("ChainRing", wheels.chainring))
.position(by: .value("ChainRing", i))
}
}
.chartXAxis {
AxisMarks (values: .stride (by: 1)) { value in
AxisValueLabel()
}
}
.padding()
}
}