I am trying to Sum the SwiftData Ints found on the same date and display the result in a chart.
The following shows the individual records on the date in a chart just fine, I just need to add them before displaying the point.
Any help?
Here is my code.
Thanks.
Blessings,
–Mark
@Query(filter: #Predicate<Register>
{ $0.sundayAdded }, sort: [SortDescriptor(.date)]
) var fetchedData: [Register]
Chart(fetchedData) { item in
if item.sundayAdded {
LineMark(
x: .value( "Date", item.date, unit: .day),
y: .value( "ASA", Double(item.sunCount))).opacity(0.3)
PointMark(
x: .value( "Date", item.date, unit: .day),
y: .value( "ASA", Double(item.sunCount)))
.annotation {
Text("(item.sunCount)")
.font(.caption2)
}
}
}