I am trying to make my Int enum conform to Plottable in order to use a legend in my Swift Charts. I'm not sure if I've understood the way on how to implement it correctly. Here is how my enum:
enum Type: Int, CaseIterable, Identifiable, Plottable {
init?(primitivePlottable: Int) {
self.init(rawValue: primitivePlottable)
}
var primitivePlottable: Int {
return rawValue
}
var id: Int {
return rawValue
}
case first = 32
case second = 434
}
}
My chart looks like this:
Chart {
if let allObejcts = object.objects(type: Type.first) {
ForEach(allObejcts) { object in
BarMark(
x: .value("#", object.indexInSegment),
y: .value("Distance", object.distance)
)
.foregroundStyle(by: .value("type", object.type))
}
}
}
.chartLegend(position: .bottom, spacing: 8)
.chartLegend(SwiftUI.Visibility.visible)
.chartForegroundStyleScale([
Type.first: Color.pink,
Type.second: Color.yellow
])
.frame(minHeight: 200)
Despite compiling and running with no errors, the legends isn't visible. ♂️