Saturday, October 14, 2023
HomeiOS Developmentios - SwiftUI chart line mark being one steady line

ios – SwiftUI chart line mark being one steady line


i am very new to ios improvement, i am fetching knowledge from firebase and processing it into two arrays filled with tuples at present(Will finally be 3). the x axis is the primary worth within the tuple and so forth, every tuple ought to be some extent of the road and every array is one line.

Chart {
            ForEach(listOfEv.indices, id: .self) { index in
                LineMark(
                    x: .worth("Time", Float(listOfEv[index].time)),
                    y: .worth("EV", Float(listOfEv[index].ev))
                    
                ).foregroundStyle(
                    .linearGradient(
                        // You'll be able to have extra colors right here is dependent upon your knowledge.
                        colours: [.blue, .red],
                        startPoint: .backside,
                        endPoint: .high)
                )
                
                PointMark(
                    x: .worth("Time", Float(listOfEv[index].time)),
                    y: .worth("EV", Float(listOfEv[index].ev))
                )
                
            }
            
            ForEach(listOfAv.indices, id: .self) { index1 in
                LineMark(
                    x: .worth("Time", Float(listOfAv[index1].time)),
                    y: .worth("EV", Float(listOfAv[index1].ev))
                ).foregroundStyle(.inexperienced)
                PointMark(
                    x: .worth("Time", Float(listOfAv[index1].time)),
                    y: .worth("EV", Float(listOfAv[index1].ev))
                )
            }
            
            
        }.foregroundStyle(.inexperienced)
            .body(width: .infinity,peak: 300)
            .onAppear(carry out: {
                firebaseData.BetTracker(username: "rozzaroo", completion: { EvData, AvData, SpData in
                    
                    listOfAv = AvData
                    listOfSp = SpData
                    listOfEv = EvData
                    
                })
            })
     

That is the chart i am utilizing to show the information

unc BetTracker(username: String, completion: @escaping ([(Int, Int)], [(Int, Int)], [(Int, Int)]) -> Void) {
        
        let ref = Database.database().reference().baby("customers").baby(username.lowercased()).baby("bets")
        
        ref.observeSingleEvent(of: .worth) { snapshot, error in
            if let error = error {
                print("Error fetching odds record: (error)")
                return
            }
            
            if let knowledge = snapshot.worth as? [String: Any] {
                let keysCount = knowledge.keys.depend
                var processedKeys = 0
                var EvCounter = 0
                var AvCounter = 0
                var time = 0
                
                let sortedKeys = knowledge.keys.sorted {
                    guard let first = knowledge[$0] as? [Any], let second = knowledge[$1] as? [Any],
                          let firstInt = first[1] as? Int, let secondInt = second[1] as? Int else { return false }
                    return firstInt < secondInt
                }
                
                for key in sortedKeys {
                    if let usersBetTrack = knowledge[key] as? [Any] {
                        let refMaster = Database.database().reference().baby("Grasp").baby(key)
                        
                        refMaster.observeSingleEvent(of: .worth) { caughtBet, error in
                            processedKeys += 1
                            
                            if let error = error {
                                print("Error fetching knowledge: (error)")
                                return
                            }
                            
                            if caughtBet.exists() {
                                if let array = caughtBet.worth as? [AnyObject], let evMaster = array.first as? String,
                                   let userBetAmtTrack = usersBetTrack[2] as? String,
                                   
                                    let betTimePlace1 = usersBetTrack[1] as? Int {
                                    if let userBookOdd = usersBetTrack[3] as? String {
                                        var userBookOdds = Float(userBookOdd)
                                        
                                        
                                        var updatedEvMaster = Float(evMaster.dropLast())! / 100
                                        var dollarAmountBet = Float(userBetAmtTrack.dropFirst())!
                                        dollarAmountBet *= updatedEvMaster
                                        let currentTimeZone = TimeZone.present
                                        let gmtOffsetInSeconds = currentTimeZone.secondsFromGMT()
                                        var betTimePlace2 = betTimePlace1 + gmtOffsetInSeconds
                                        
                                        EvCounter = Int(dollarAmountBet) + EvCounter
                                        EvCounter = Int(EvCounter)
                                        
                                        time = 1 + time
                                        
                                        if let gameResult = array[12] as? String {
                                            
                                            swap (gameResult) {
                                            case "win":
                                                var usersStake = Float(userBetAmtTrack.dropFirst())
                                                usersStake = (userBookOdds! - 1) * usersStake!
                                                AvCounter = AvCounter + Int(Float(usersStake!))
                                                
                                            case "lose":
                                                AvCounter = AvCounter - Int(Float(userBetAmtTrack.dropFirst())!)
                                            case "pending":
                                                AvCounter = AvCounter + 0
                                            default:
                                                AvCounter = AvCounter + 0
                                            }
                                        }
                                        
                                        time = time + 1
                                        self.AvList.append((time: Int(time), ev: AvCounter))
                                        self.EvList.append((time: Int(time), ev: EvCounter))
                                        
                                        // Verify if all keys have been processed, then name the completion handler
                                        if processedKeys == keysCount {
                                            
                                            completion(self.EvList, self.AvList, self.SpList)
                                        }
                                    }
                                }
                            } else {
                                print("Snapshot doesn't exist")
                            }
                        }
                    }
                }
            }
        }
    }

all my knowledge is appropriate and sorted with the bottom x axis worth coming first within the array.

at present that is what the road appears like, i need it to be 2 seperate strains. i am very caught and not sure how you can make them not related

enter image description here



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments