How to reverse a custom Domain in Swift Charts?

I'm currently building an app in SwiftUI that needs to show some charts. Swift Charts has been quite helpful but I can't seem to set the domain of the chart just how I want it. The following chart display events that happend in a week and I want to display every hour even if nothing happened there, and I want the hours to go up, instead of the default where the new day start at the top of the chart.

struct ChartView: View {
  let dataSets: [someData]
  // simplified date init
  let datemin = date(year:2025, month: 2, day: 24)
  let datemax = date(year:2025, month: 2, day: 25)
  var body: some View {
    Chart(dataset) { data in
      PointMark(x: .value("Day", data.day, unit: .weekday),
                         y: .value("Time", data.time, unit: .minute))
      }
    }
  // The focus is on this line
  .chartYScale(domain: .automatic(reversed: true))
  }
}

The .chartYScale(domain:) modifier allows me to set the start of the day at the bottom, but still ignores some hours.

If I instead use this

Chart(...) { ... }
.chartYScale(domain: datemin...datemax)

The chart display every hour of the day, but now the start of the day is at the bottom. I can't seem to find a way to get both things at the same time. if I add both modifiers only the first one get applied while the other ignored.

Any solutions or workarounds?

Which hours are ignored in the first case ? They all seem visible (except 24, but 24 is also 0…)

datemin and datermax seem to apply more appropriate for xAxis than yAxis.

Did you try:

Chart(...) { ... }
.chartYScale(domain: [0, 24])

The first screenshot doesn't display the 24th hour (hour 0 for the next day), because there is no event that happened between 23:00 and 23:59. If there were no events between 00:00 to 08:00, those hours would not appear on the chart if I don't set the domain myself.

Using [0,24] did not work as the time is entered as a Date type, so using [datemax, datemin])did the trick. Thanks! Didn't see that option anywhere, where did you find it or how do you know that it was posible to do that?.

How to reverse a custom Domain in Swift Charts?
 
 
Q