Open kdthomas2121 opened 3 years ago
@kdthomas2121 I have same problem. Did you found solution how to force update chart?
@kdthomas2121 I am having the same problem. Did you find any solution to this problem yet? thanks in advance!
@kdthomas2121 I am having the same problem. Did you find any solution to this problem yet? thanks in advance!
What did you do?
Create a graph inside a UIViewRepresentable with an @ObservedObject viewModel
Attempted the below update code, which does not work
func updateUIView(_ uiView: LineChartView, context: UIViewRepresentableContext<LineChartSwiftUI>) { chart.data = addData() chart.data?.notifyDataChanged() chart.notifyDataSetChanged() chart.animate(xAxisDuration: 0.01) }
What did you expect to happen?
When the @Published data within the view model changes, the graph should reload
What happened instead?
Nothing
Charts Environment
Latest Xcode Version 12.2 SwiftUI Platform(s) running Charts: Big sur `struct LineChartSwiftUI: UIViewRepresentable { @ObservedObject var viewModel: viewModel
func makeUIView(context: UIViewRepresentableContext) -> LineChartView {
let chart = LineChartView()
chart.data = addData()
updateChart()
}
}
`
Within my view:
case .loaded(let data): VStack { LineChartSwiftUI(viewModel: viewModel) }