0

How can I get SwiftUI Chart to display a daily average vs the sum if I were using .weekOfYear as the unit for BarMark? For example, instead of displaying the total number of steps in a week, I'd like to show the daily average for that week.

Chart {
            ForEach(stats, id: \.time) { stat in
                BarMark(
                    x: .value("Time", stat.time, unit: .weekOfYear),
                    y: .value("Steps", stat.value)
                )
            }
        }
Tuan Anh Vu
  • 760
  • 1
  • 7
  • 26
  • 1
    you could write a `func getAverage() -> Double{...}` for the `stat` that returns the average for a given time, and use that in the `Chart`, like: `... y: .value("Steps", stat.getAverage())` – workingdog support Ukraine Jun 23 '23 at 01:12

0 Answers0