I'm having an issue with SwiftUI charts and was wondering if anyone knows of a solution or has also run into this. I've been trying to plot data for my app and the X axis does not show the dates and the Y axis only has axis marks 0-9. So, I tried to make another file instance to check what's going on. This is what I have
import Charts
import SwiftUI
struct Exercise: Identifiable {
let id = UUID()
var dateCompleted: Date
var reps: Int
}
struct ContentView: View {
private var exerciseMaxRepsArray: [Exercise] = []
init() { // init dummy data
for i in 0 ..< 20 {
let date = Calendar.current.date(byAdding: .day, value: i, to: .now) ?? .now
let rep = Int.random(in: 1...20)
exerciseMaxRepsArray.append(
Exercise(dateCompleted: date, reps: rep)
)
}
}
var body: some View {
GroupBox(label: Text("Daily Max Reps")) {
Chart(exerciseMaxRepsArray) { e in
LineMark(x: .value("Date", e.dateCompleted, unit: .day),
y: .value("Reps", e.reps)
) }
.chartYAxisLabel(position: .trailing, alignment: .center) {
Text("Reps")
}
.chartXAxisLabel(position: .bottom, alignment: .center) {
Text("Date")
}
}
and this is the result:
I've checked and the issue is not the frame. Has anyone else had this issue or have any clue what could be going on here?