ios – Swift Charts: Tips on how to shade a highlighted space in a line chart?


enter image description hereThe code under attracts a RuleMark on the high and backside of the realm I wish to spotlight, nonetheless, as an alternative of two strains I wish to shade this space gray to point out the conventional vary. How can I do that?

import SwiftUI
import Charts

struct ContentView: View {
    
    struct StepCount: Identifiable {
        let id = UUID()
        let weekday: Date
        let steps: Int
        
        init(day: String, steps: Int) {
            let formatter = DateFormatter()
            formatter.dateFormat = "yyyyMMdd"
            
            self.weekday = formatter.date(from: day) ?? Date.distantPast
            self.steps = steps
        }
    }
    
    let currentWeek: [StepCount] = [
        StepCount(day: "20220717", steps: 4200),
        StepCount(day: "20220718", steps: 15000),
        StepCount(day: "20220719", steps: 2800),
        StepCount(day: "20220720", steps: 10800),
        StepCount(day: "20220721", steps: 12370),
        StepCount(day: "20220722", steps: 9500),
        StepCount(day: "20220723", steps: 3700)
    ]
    
    var physique: some View {
        VStack {
            Chart {
                ForEach(currentWeek) {
                    LineMark(
                        x: .worth("Week Day", $0.weekday, unit: .day),
                        y: .worth("Step Depend", $0.steps)
                    )
                }
                RuleMark(y: .worth("Max of Vary", 10000))
                    .foregroundStyle(.purple)
                RuleMark(y: .worth("Min of Vary", 6000))
                    .foregroundStyle(.purple)
            }
        }
        .body(top: 200)
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}[![enter image description here][1]][1]

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles