I am trying to implement a horizontal scrollable chart. However, the y axis moves along when scrolling. How can I make the y axis stay put?
Here is my code:
struct DataPoint: Identifiable {
var id = UUID()
let x: Double
let y: Double
}
let minGlobalX: Double = 0
let maxGlobalX: Double = 100
let data: [DataPoint] = (Int(minGlobalX) ..< Int(maxGlobalX)).map { DataPoint(x: Double($0), y: Double(arc4random()) / Double(UInt32.max)) }
struct ContentView: View {
var body: some View {
Chart(data) {
LineMark(
x: .value("x", $0.x),
y: .value("y", $0.y)
)
.lineStyle(StrokeStyle(lineWidth: 1))
}
.chartScrollableAxes(.horizontal)
.chartXScale(domain: [minGlobalX, maxGlobalX])
.chartXAxis {
AxisMarks(position: .bottom, values: [0]) {
AxisGridLine(stroke: .init(lineWidth: 1))
}
}
.chartYScale(domain: [0, 1])
.chartYAxis {
AxisMarks(position: .leading, values: [0]) {
AxisGridLine(stroke: .init(lineWidth: 1))
}
}
.padding(20)
}
}