I'm doing FetchRequest
@Environment(\.managedObjectContext) var managedObjContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.date, order: .reverse)])
var day: FetchedResults<Item>
And then I put it in Charts, but Swift Charts need Plottable, and it seems to me that there is no way to convert it.
Help, please!
Trying to do this kind of thing, but it doesn't work. Mistake: Cannot convert value of type '() -> BarMark' to expected argument type '(FetchedResults.Element) -> BarMark' (aka '(Item) -> BarMark'). I should convert my core data to Plottable, I think, ad I don't no how.
import SwiftUI
import Charts
struct ChartView: View {
@Environment(\.managedObjectContext) var managedObjContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.date, order: .reverse)]) var day: FetchedResults<Item>
@State var low = 0
@State var top = 0
@State var ir = 0
@State var date = Date()
var body: some View {
Chart(day) {
BarMark(
x: .value("Day", low),
y: .value("Sales", top)
)
}
}
}