1.3 C
Sunday, March 3, 2024

ios – Hiding a zero annotation on a Swift Charts donut chart

I’ve made a donut chart in Swift Charts. It could possibly have 3 segments representing objects within the person’s knowledge with issues (purple), warnings (orange) or regular objects (secondary / impartial color).

Typically the segments may need a zero worth, however I’ve observed that the annotation nonetheless shows zero and it seems to be messy. I wish to cover this.

On this picture, the zero annotation of the absent orange section is circled in blue.

Donnut chart with unwanted zero annotation highlighted in blue

Right here is my code:

Chart(knowledge, id: .class) { ingredient in
    Plot {
            angle: .worth("Depend", ingredient.depend),
            // These settings make the purple and orange sections extra distinguished
            innerRadius: .inset(ingredient.class == .Nominal ? 32 : 40),
            outerRadius: .inset(ingredient.class == .Nominal ? 8 : 0),
            angularInset: 2.0
            .foregroundStyle(by: .worth("Class", ingredient.class.rawValue))
            // Right here is the styling for the annotations
            .annotation(place: .overlay, alignment: .heart) {
                Textual content("(ingredient.depend)")
            .accessibilityValue("(ingredient.depend) objects")
            area: IssueCategory.allCases,
            vary: [.red, .orange, .secondary.opacity(0.5)]
        .chartPlotStyle { plotArea in
        .chartXScale(area: 0...medication.depend)
        .chartYScale(vary: .plotDimension(endPadding: -8))
        .chartBackground { proxy in
            Textual content("(medication.depend)")
            .body(top: 196)

In abstract, I am hoping to cover the annotation (a quantity label in my case) whether it is zero and thus it is section isn’t being displayed.

Latest news
Related news


Please enter your comment!
Please enter your name here