This works
var dataMultiLine: [LocationData.Series] {
LocationData.last30Days
}
struct MultiLineView: View {
var body: some View {
VStack {
Chart {
ForEach(dataMultiLine) { series in
ForEach(series.sales, id: \.day) { element in
LineMark(
x: .value("Day", element.day, unit: .day),
y: .value("Sales", element.sales)
)
}
.foregroundStyle(by: .value("City", series.city))
.symbol(by: .value("City", series.city))
.interpolationMethod(.catmullRom)
}
}
}
.padding()
}
}
This doesn't work
var dataContent: [MonthlyHoursOfSunshine] = [
MonthlyHoursOfSunshine(city: "Cupertino", month: 1, hoursOfSunshine: 196),
MonthlyHoursOfSunshine(city: "Seattle", month: 1, hoursOfSunshine: 74),
MonthlyHoursOfSunshine(city: "Seattle", month: 12, hoursOfSunshine: 62),
MonthlyHoursOfSunshine(city: "Cupertino", month: 12, hoursOfSunshine: 199),
]
struct ContentView: View {
var body: some View {
VStack {
Chart(dataContent) {
LineMark(
x: .value("Month", $0.date),
y: .value("Hours of Sunshine", $0.hoursOfSunshine)
)
.foregroundStyle(by: .value("City", $0.city))
.symbol(by: .value("City", $0.city))
}
}
.padding()
}
}
Christian
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: