ChartView icon indicating copy to clipboard operation
ChartView copied to clipboard

Create Data structure

Open AppPear opened this issue 5 years ago • 2 comments

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 x and y value.
  • y value must be numeric (possibly floating point number)
  • x can be numeric or string
  • has to be at least 3 initialisers: 1) only y values, 2) x and y numeric values 3) x string and y numeric values
  • changes in the source are reflected in the charts automatically

More info: #89

AppPear avatar May 24 '20 19:05 AppPear

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]))

satan87 avatar May 31 '20 18:05 satan87

PR #112 I manage to arrive at the result by using Binding, all the way.

satan87 avatar Jun 01 '20 01:06 satan87