Environment: Xcode 14.1 beta 3 on macOS Ventura Beta 9.
No longer need this, I found example of this.
struct LocationsChart: View {
var body: some View {
Chart {
ForEach(seriesData, id: \.city) { series in
ForEach(series.data, id: \.weekday) {
BarMark(
x: .value("Weekday", $0.weekday, unit: .day),
y: .value("Sales", $0.sales)
)
}
.foregroundStyle(by: .value("City", series.city))
.position(by: .value("City", series.city))
}
}
}
let seriesData = [
(
city: "Cupertino", data: [
(weekday: date(year: 2022, month: 5, day: 2), sales: 54),
(weekday: date(year: 2022, month: 5, day: 3), sales: 42),
(weekday: date(year: 2022, month: 5, day: 4), sales: 88),
(weekday: date(year: 2022, month: 5, day: 5), sales: 49),
(weekday: date(year: 2022, month: 5, day: 6), sales: 42),
(weekday: date(year: 2022, month: 5, day: 7), sales: 125),
(weekday: date(year: 2022, month: 5, day: 8), sales: 67)
]
),
(
city: "San Francisco", data: [
(weekday: date(year: 2022, month: 5, day: 2), sales: 81),
(weekday: date(year: 2022, month: 5, day: 3), sales: 90),
(weekday: date(year: 2022, month: 5, day: 4), sales: 52),
(weekday: date(year: 2022, month: 5, day: 5), sales: 72),
(weekday: date(year: 2022, month: 5, day: 6), sales: 84),
(weekday: date(year: 2022, month: 5, day: 7), sales: 84),
(weekday: date(year: 2022, month: 5, day: 8), sales: 137)
]
)
]
}
func date(year: Int, month: Int, day: Int = 1) -> Date {
Calendar.current.date(from: DateComponents(year: year, month: month, day: day)) ?? Date()
}