Ok. I have paired it all the way back to a single page of code.
You can see the text at the top of the graph is the Y coords and it doesn't match the chart. If I had included interactivity then tapping on the graph would make it show the correct chart.
Code:
import SwiftUI
import Charts
struct Point: Identifiable {
var x: Int
var y: Int
let id = UUID()
}
struct PointData: Identifiable {
var points: [Point]
let id = UUID()
}
struct TabSelectorView: View {
var pointDataArray: [PointData] = []
init() {
self.pointDataArray = initData()
}
var body: some View {
let data = pointDataArray
VStack {
TabView {
ForEach((0..<data.count), id: \.self) { index in
VStack {
let graphData = pointDataArray[index]
Text (graphData.points.map { String($0.y) }.joined(separator: ","))
Chart(graphData.points) { item in
LineMark(
x: .value("X", item.x),
y: .value("Y", item.y)
)
.symbol {
Circle()
.fill(Color.orange)
.frame(width: 10)
}
}
}
.tag((index))
}
}
.tabViewStyle(.page)
.indexViewStyle(.page(backgroundDisplayMode: .always))
}
}
func initData() -> [PointData] {
var ret: [PointData] = []
for chartNum in 0...6 {
var pointArray: [Point] = []
for point in 0...5 {
pointArray.append(Point(x: point, y: point + chartNum))
}
ret.append(PointData(points: pointArray))
}
return ret
}
}
#Preview {
return TabSelectorView()
.frame(height: 400)
.padding(50)
}
Am I doing something obviously wrong?!
Note that some tab pages are correct and others are incorrect, and it changes as you swipe through.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: