Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Charts: poor performance when synchronizing scrolling among multiple charts
Try to move your Charts into subviews, and their bodies won't be called on markerValue change. struct SpeedChartView: View { var data: [DataPoint] var body: some View { Chart(data) { LineMark( x: .value("Time", $0.xValue), y: .value("Speed", $0.yValue) ) } } } struct LatChartView: View { var data: [DataPoint] var body: some View { Chart(data) { LineMark( x: .value("Time", $0.xValue), y: .value("LatG", $0.yValue) ) } } } struct DataTraceView: View { @State var testVector1: [DataPoint] = generateRandomDataPoints(count: SAMPLES) @State var testVector2: [DataPoint] = generateRandomDataPoints(count: SAMPLES) @Binding var markerValue: Double var body: some View { VStack { SpeedChartView(data: testVector1) .chartScrollPosition(x: $markerValue) .chartXVisibleDomain(length: 15) .chartScrollableAxes(.horizontal) LatChartView(data: testVector2) .chartScrollPosition(x: $markerValue) .chartXVisibleDomain(length: 15) .chartScrollableAxes(.horizontal) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’23