Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Charts: poor performance when synchronizing scrolling among multiple charts
Hello, I have stumbled on a similar issue where the scrolling performance of the chart terrible although I am not synchronizing the scroll position between multiple charts but trying to get the scroll position for a single chart. What solved the performance issue for me was moving the data and the scroll position variable to an Observable class. struct TimelineChart: View { @Bindable var viewModel: ViewModel var body: some View { Chart(viewModel.segments) { segment in BarMark( xStart: .value("Timestamp", segment.startTimestamp), xEnd: .value("Timestamp", segment.endTimestamp) ) .foregroundStyle(segment.color) } .chartScrollPosition(x: $viewModel.selectedTimestamp) .chartScrollableAxes(.horizontal) .fixedSize(horizontal: false, vertical: true) } } @Observable class ViewModel { init(segments: [Activity.Segment]) { self.segments = segments selectedTimestamp = segments.first!.startTimestamp } let segments: [Activity.Segment] var selectedTimestamp: Date } Hopefully it also helps you if you are still having this issue.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24