ChartView
ChartView copied to clipboard
Create Data structure
v2 ticket
Ticket description:
This should hold and handle the values for charts. You should create it in a way that changes in the source data can be automatically reflected in the charts.
- should be a structure which can hold a
xandyvalue. -
yvalue must be numeric (possibly floating point number) -
xcan be numeric or string - has to be at least 3 initialisers: 1) only
yvalues, 2)xandynumeric values 3) xstringandynumeric values - changes in the source are reflected in the charts automatically
More info: #89
I did a simple test.
import SwiftUI
import SwiftUICharts
struct ContentView: View {
@State var data: [Double] = [1, 2, 3]
var body: some View {
VStack {
CardView {
ChartView(data: self.data)
ChartLabel("Test \(self.data[0])")
}
Button(action: {
self.data[0] += 1
print(self.data[0])
}) {
Text("Click to add")
}
}
}
}
I can see the value of the ChartLabel being updated. But the graph is not being updated...
I manage to have the BarCell, and BarChart update using Binding for the value instead of State. But still, when using ChartView, there is no update.
Should we use @EnvironmentObject, and move to somehing like this: ChartView().environmentObject(DataControler(Data: [1,2,3]))
PR #112 I manage to arrive at the result by using Binding, all the way.