TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Charts in SwiftUI

Forums > SwiftUI

@Genka  

I'm a beginner developer! Please help me add the updating data to the chart, while I do not understand how to do it Here is my code I need the data var amount: Double

import SwiftUI
import SwiftData

@Model
class ConsumableProperty {
    /// Расходные свойства
    var title: String
    var subTitle: String
    var amount: Double
    var date: Date

    // Категория расходов
    var category: Category?

    init(title: String, subTitle: String, amount: Double, date: Date,category: Category? = nil) {
        self.title = title
        self.subTitle = subTitle
        self.amount = amount
        self.date = date
        self.category = category

    }
    // Строка валюты
    @Transient
    var currencyString: String {
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        return formatter.string (for: amount) ?? ""
    }
}

I need to add a value var amount: Double instead of values amountSpent: 5540

import SwiftUI
import Charts
import SwiftData

struct CostAnalytics: View {

    let viewMonths: [ViewMonth] = [
        .init(date: Date.from(year: 2023, month: 1, day: 1), amountSpent: 5540),
        .init(date: Date.from(year: 2023, month: 2, day: 1), amountSpent: 6560),
        .init(date: Date.from(year: 2023, month: 3, day: 1), amountSpent: 10),
        .init(date: Date.from(year: 2023, month: 4, day: 1), amountSpent: 850),
        .init(date: Date.from(year: 2023, month: 5, day: 1), amountSpent: 50),
        .init(date: Date.from(year: 2023, month: 6, day: 1), amountSpent: 250),
        .init(date: Date.from(year: 2023, month: 7, day: 1), amountSpent: 350),
        .init(date: Date.from(year: 2023, month: 8, day: 1), amountSpent: 65),
        .init(date: Date.from(year: 2023, month: 9, day: 1), amountSpent: 250),
        .init(date: Date.from(year: 2023, month: 10, day: 1), amountSpent: 350),
        .init(date: Date.from(year: 2023, month: 11, day: 1), amountSpent: 950),
        .init(date: Date.from(year: 2023, month: 12, day: 1), amountSpent: 500)
    ]

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.