Monday, February 12, 2024
HomeiOS Developmentios - Swift Chart Axis ordering situation

ios – Swift Chart Axis ordering situation


that tracks somebody’s sleep into the 4 classes awake, rem, core and deep. I’ve the graph nearly how I need it, exhibiting the sleep information at varied occasions of the evening (every hour), nonetheless I’m misplaced on how I’m meant to get my Y axis exhibiting in the suitable order. I need it break up into 4, for every of the sleep levels, beginning prime awake, under REM, under core, on the backside deep, 25% of the peak of the graph. Nonetheless, it doesn’t matter what I strive, it maintains the order core, awake, deep, REM. I’ve tried utilizing the .chartYAxis, nevertheless it didnt appear to do something. I can see within the documentation the best way to alter this for numbers, or dates, however for what I need, I’m fairly misplaced, particularly as I get no errors, it simply fails silently to organize them. I thought of by some means utilizing an Integer to signify every of the sleep sorts, 0 = awake, 4 = deep, and by some means correspond these to a String worth, however I’m not positive the best way to obtain that. Thanks for the assistance!

enum SleepType: String, Plottable {
    case Awake
    case REM
    case Core
    case Deep
}

struct SingleSleep: Hashable, Identifiable {
    let id = UUID()
    let startDate: Date
    let stopDate: Date
    var sleepTime: TimeInterval = 0 //in minutes
    var sleepType: SleepType
}     

Chart {
   ForEach(sleep, id: .self) { sleep in
      LineMark(
               x: .worth("Time", sleep.startDate),
               y: .worth("Sort", sleep.sleepType.rawValue)
               )
       }
}
.chartXAxis {
   AxisMarks(values: .stride(by: .hour, rely: 1)) { worth in
      AxisValueLabel(format: .dateTime.hour(), centered: true)
      }
}
.chartYAxis {
   AxisMarks(
      values: [SleepType.Awake.rawValue, SleepType.REM.rawValue, SleepType.Core.rawValue,    SleepType.Core.rawValue]
)
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments