ChartContent
A type that represents the content that you draw on a chart.
Declaration
@MainActor @preconcurrency protocol ChartContentOverview
You build a Chart by adding instances that conform to the ChartContent protocol to the chart’s content closure. The following example adds three explicit BarMark instances to a chart:
Chart {
BarMark(
x: .value("Shape Type", "Cube"),
y: .value("Total Count", 5)
)
BarMark(
x: .value("Shape Type", "Sphere"),
y: .value("Total Count", 6)
)
BarMark(
x: .value("Shape Type", "Pyramid"),
y: .value("Total Count", 4)
)
}The chart draws marks that correspond to the instances that you specify:
[Image]
You can combine any number of marks or types of marks in a single chart by listing them individually as shown in the above example, wrapping them in a ForEach, or any combination of these. For some mark types, like LineMark, you can group the marks into series using the mark’s series initialization parameter.
Configure chart content
The ChartContent protocol provides a set of modifiers that you use to configure the properties of chart content. These behave like SwiftUI view modifiers, except that they act on chart content rather than views. Any of the types that conform to the protocol can use these modifiers. For example, you can add the foregroundStyle(_:) modifier to the bar representing the number of spheres in the previous example to make it red:
BarMark(
x: .value("Shape Type", "Sphere"),
y: .value("Total Count", 6)
)
.foregroundStyle(.red)[Image]
Topics
Styling marks
foregroundStyle(_:)opacity(_:)blur(radius:)cornerRadius(_:style:)lineStyle(_:)shadow(color:radius:x:y:)interpolationMethod(_:)
Positioning marks
offset(_:)offset(x:y:)offset(x:yStart:yEnd:)offset(xStart:xEnd:y:)offset(xStart:xEnd:yStart:yEnd:)alignsMarkStylesWithPlotArea(_:)
Setting symbol appearance
Encoding data into mark characteristics
Annotating marks
annotation(position:alignment:spacing:content:)annotation(position:alignment:spacing:content:)annotation(position:alignment:spacing:overflowResolution:content:)annotation(position:alignment:spacing:overflowResolution:content:)
Layering chart content
Masking and clipping
Configuring accessibility
accessibilityHidden(_:)accessibilityIdentifier(_:)accessibilityLabel(_:)accessibilityLabel(_:)accessibilityLabel(_:)accessibilityLabel(_:)accessibilityValue(_:)accessibilityValue(_:)accessibilityValue(_:)accessibilityValue(_:)