I have a SwiftUI LineMark chart that inverts the y axis when the data the chart is plotting is all zeros. I'm expecting the y axis 0 to be at the bottom but when the data is all zeros it's at the top. Below is an example demonstrating the problem:
import SwiftUI import Charts
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])
)
}
}
.chartYAxis {
AxisMarks(values: [0, 10, 20, 30, 40, 50]) { value in
AxisValueLabel()
AxisTick()
AxisGridLine()
}
}
.padding()
}
}
I can't use .chartYScale(domain: ) because it overrides the chartYAxis where the real code creates custom a leading and trailing y axis.
Does anyone have any suggestions how I may fix this?
Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. Please file a bug report, include a small Xcode project and some directions that can be used to reproduce the problem, and post the FB number here once you do.
Bug Reporting: How and Why? has tips on creating your bug report.