0

I don't know where to start on this problem. I created a scrollable horizontal chart that shows health data. But is there a way to tap on any of these vitals to then change them manually?

Here's my code I want to modify to use gestures:

import SwiftUI
import Charts

struct Vitals {
    var time: Int
    var pulse: Int
    var SBP: Int
}

var data: [Vitals] = [
    Vitals(time: 5, pulse: 74, SBP: 129),
    Vitals(time: 10, pulse: 68, SBP: 113),
    Vitals(time: 15, pulse: 73, SBP: 88),
    Vitals(time: 20, pulse: 78, SBP: 92),
    Vitals(time: 25, pulse: 70, SBP: 103),
    Vitals(time: 30, pulse: 69, SBP: 97),
    Vitals(time: 35, pulse: 78, SBP: 92),
    Vitals(time: 40, pulse: 70, SBP: 103),
    Vitals(time: 45, pulse: 69, SBP: 97),
    Vitals(time: 50, pulse: 78, SBP: 92),
    Vitals(time: 55, pulse: 70, SBP: 103),
    Vitals(time: 60, pulse: 69, SBP: 97),
    Vitals(time: 65, pulse: 70, SBP: 103),
    Vitals(time: 70, pulse: 69, SBP: 97),
    Vitals(time: 75, pulse: 78, SBP: 92)
]

struct ContentView: View {
    
//    @State mytable(9, 7)
    
    var body: some View {
        
        ScrollView(.horizontal) {
            VStack {
//                Table(selection: $table, columns: <#T##() -> _#>, rows: <#T##() -> _#>)
                HStack(spacing: 10) {
                    ForEach(0..<10) {
                        Text("Item \($0)")
                            .foregroundColor(.white)
                            .font(.largeTitle)
                            .frame(width: 200, height: 200)
                            .background(.red)
                    }
                }
                Chart(data, id: \.time) {
                    PointMark(
                        x: .value("Time", $0.time),
                        y: .value("Pulse", $0.pulse)
                    )
                    .foregroundStyle(.red)
                    PointMark(
                        x: .value("Time", $0.time),
                        y: .value("SBP", $0.SBP)
                    )
                    .annotation(position: .overlay, alignment: .center) {
                        VStack(spacing: 4) {
                            Image(systemName: "chevron.down")
                        }
                    }
                    .symbolSize(0)
                    PointMark(
                        x: .value("Time", $0.time),
                        y: .value("DBP", $0.SBP-45)
                    )
                    .annotation(position: .overlay, alignment: .center) {
                        VStack(spacing: 4) {
                            Image(systemName: "chevron.up")
                        }
                    }
                    .symbolSize(0)
                }
                .background(Color(hue: 0.10, saturation: 0.10, brightness: 0.98))
                .frame(width: 2000, height: 400)
                .padding(30)
                .chartYAxis() {
                    AxisMarks(position: .leading)
                }
                
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

What would I call this that I am looking for - are they a form of interactive charts?

mgianzero
  • 87
  • 5
  • Does this answer your question? [How to change the color of BarView in SwiftUI charts when we tap on it](https://stackoverflow.com/questions/74979520/how-to-change-the-color-of-barview-in-swiftui-charts-when-we-tap-on-it) – ricardopereira Aug 31 '23 at 13:33

0 Answers0