Very strange indeed.
I've tried using RuleMark as explained here: https://stackoverflow.com/questions/78873602/reverse-y-axis-of-swiftui-chart
But get the same flipping.
It does not occur if all values are equal but non zero:
let data: [Double] = [10, 10, 10, 10, 10]
Looks like a side effect of a "zero divide" (between the default minimum zero of y axis and the found max which is also 0) : when all values are equal, it wrongly computes the orientation (as you will see, chartYScale corrects this by providing the orientation).
You should file a bug report.
I found a solution using chartYScale:
struct ChartView: View {
let data: [Double] = [0, 0, 0, 0, 0]
var body: some View {
Chart {
ForEach(data.indices, id: \.self) { index in
LineMark(
x: .value("Index", index),
y: .value("Value", data[index])
)
}
}
.chartYScale(domain: [0, 50]) // <<-- Added this
.chartYAxis {
AxisMarks(values: [0, 10, 20, 30, 40, 50]) { value in
AxisValueLabel()
AxisTick()
AxisGridLine()
}
}
.padding()
}
}