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.
Right here is my code:
Chart(knowledge, id: .class) { ingredient in
Plot {
SectorMark(
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
)
.cornerRadius(4)
.foregroundStyle(by: .worth("Class", ingredient.class.rawValue))
// Right here is the styling for the annotations
.annotation(place: .overlay, alignment: .heart) {
Textual content("(ingredient.depend)")
.font(.title3)
.fontWeight(.semibold)
.foregroundStyle(Coloration.systemGroupedBackground.opacity(0.8))
}
}
.accessibilityLabel(ingredient.class.rawValue.capitalized)
.accessibilityValue("(ingredient.depend) objects")
}
.chartForegroundStyleScale(
area: IssueCategory.allCases,
vary: [.red, .orange, .secondary.opacity(0.5)]
)
.chartPlotStyle { plotArea in
plotArea
.background(Coloration.clear)
.cornerRadius(8)
}
.accessibilityChartDescriptor(self)
.chartXAxis(.seen)
.chartXScale(area: 0...medication.depend)
.chartYScale(vary: .plotDimension(endPadding: -8))
.chartLegend(.hidden)
.chartBackground { proxy in
Textual content("(medication.depend)")
.font(.title)
.fontWeight(.semibold)
.foregroundStyle(.secondary)
}
.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.