swiftuichartsplottable

SwiftUI Charts extension Image: Plottable


Is there any sensible way to create sth like extension Image: Plottable and pass to .value inside BarMark. Or there is any other possibility to have images below charts instead text?

I try sth like but it of course doesn't work

extension Image: Plottable {
    
    public var primitivePlottable: String {
        ????
    }
    
    public init?(primitivePlottable: String) {
        self.init(primitivePlottable)
    }
}

Solution

  • ok i found a slightly different solution to this problem using annotation modifier with position: .bottom like:

    BarMark(x: .value("Shape Type", shape.type),
                            y:  .value("Total Count", shape.count))
                    .annotation(position: .bottom, alignment: .center, spacing: 10, content: {
                        Image(shape.type)
                            .resizable()
                            .scaledToFit()
                            .frame(width: 50, height: 50)
                    })