I'm trying to implement a chart in Swift UI based on specific dates for an expenses app. I can get the total amount per month & display each, but I'm stuck on showing payments for a specific month (.i.e last month, current month) split by weeks.
I'm fetching payment data from Firestore, but can only fetch all data rather than just for dates as far as I know?
Chart {
ForEach(paymentModel.payments) { payment in
BarMark(
x: .value("month", payment.paymentDate, unit: .weekOfMonth),
y: .value("Amount", payment.paymentAmount)
)
}
}
.frame(height: 180)
.padding()
.chartXAxis {
AxisMarks() { date in
AxisValueLabel(format: .dateTime.week(), centered: true)
}
}
.onAppear() {
self.paymentModel.getAllPayments()
}
}
}
}
Thanks!
I've used the total amount but not sure how to get show payments based only on a certain month or other criteria (like a category)