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