Swift Charts
Build data visualizations with Swift Charts targeting iOS 26+. Compose marks
inside Chart or Chart3D, configure axes and scales with view modifiers, and
use vectorized plots or 3D plots when the data calls for them.
Use the task-specific chart references routed below instead of loading every recipe.
Contents
Workflow
- Identify the analytical question, data shape, deployment target, and accessibility requirement before choosing marks.
- Select the smallest mark set and encode series, categories, scales, and domains explicitly where ambiguity matters.
- Add axes, legends, annotations, selection, or scrolling only when they improve interpretation.
- Prefer vectorized plots or aggregation for large datasets and avoid expensive per-mark decoration.
- Verify empty/single/extreme data, localization, Dynamic Type, VoiceOver summaries, selection, and performance.
Route by Task
- Read core implementation details for chart containers, marks, axes, scales, styles, selection, scrolling, annotations, vectorized plots, and 3D charts.
- Read chart types and composition for bars, lines, sectors, combined charts, and data modeling.
- Read interaction, 3D, accessibility, and performance for selection, scrolling, function plots, surfaces, and large datasets.
- Read styling, heat maps, and modifier reference for themes, symbols, stacking, coordinate conversion, and quick-reference modifiers.
Core Decisions
- Choose marks from the question being answered, not visual novelty.
- Preserve truthful scale domains and label units/aggregation clearly.
- Encode multiple line series with an explicit series dimension.
- Keep charts readable at large text sizes and expose nonvisual summaries.
Common Mistakes
1. Missing series parameter for multi-line charts
// WRONG -- all points connect into one line
Chart {
ForEach(allCities) { item in
LineMark(x: .value("Date", item.date), y: .value("Temp", item.temp))
}
}
// CORRECT -- separate lines per city
Chart {
ForEach(allCities) { item in
LineMark(x: .value("Date", item.date), y: .value("Temp", item.temp))
.foregroundStyle(by: .value("City", item.city))
}
}
2. Too many SectorMark slices
// WRONG -- 20 tiny sectors are unreadable
Chart(twentyCategories, id: \.name) { item in
SectorMark(angle: .value("Value", item.value))
}
// CORRECT -- group into top 5 + "Other"
Chart(groupedData, id: \.name) { item in
SectorMark(angle: .value("Value", item.value))
.foregroundStyle(by: .value("Category", item.name))
}
3. Missing scale domain when zero-baseline matters
// WRONG -- axis starts at ~95; small changes look dramatic
Chart(data) {
LineMark(x: .value("Day", $0.day), y: .value("Score", $0.score))
}
// CORRECT -- explicit domain for honest representation
Chart(data) {
LineMark(x: .value("Day", $0.day), y: .value("Score", $0.score))
}
.chartYScale(domain: 0...100)
4. Static foregroundStyle overriding data encoding
// WRONG -- static color overrides by-value encoding
BarMark(x: .value("X", item.x), y: .value("Y", item.y))
.foregroundStyle(by: .value("Category", item.category))
.foregroundStyle(.blue)
// CORRECT -- use only the data encoding
BarMark(x: .value("X", item.x), y: .value("Y", item.y))
.foregroundStyle(by: .value("Category", item.category))
5. Individual marks for 10,000+ data points
// WRONG -- creates 10,000 mark views; slow
Chart(largeDataset) { item in
PointMark(x: .value("X", item.x), y: .value("Y", item.y))
}
// CORRECT -- vectorized plot (iOS 18+)
Chart {
PointPlot(largeDataset, x: .value("X", \.x), y: .value("Y", \.y))
}
6. Fixed chart height breaking Dynamic Type
// WRONG -- clips axis labels at large text sizes
Chart(data) { ... }
.frame(height: 200)
// CORRECT -- adaptive sizing
Chart(data) { ... }
.frame(minHeight: 200, maxHeight: 400)
7. KeyPath modifier after value modifier on vectorized plots
// WRONG -- compiler error
BarPlot(data, x: .value("X", \.x), y: .value("Y", \.y))
.opacity(0.8)
.foregroundStyle(\.color)
// CORRECT -- KeyPath modifiers first
BarPlot(data, x: .value("X", \.x), y: .value("Y", \.y))
.foregroundStyle(\.color)
.opacity(0.8)
8. Missing accessibility labels
// WRONG -- VoiceOver users get no context
Chart(data) {
BarMark(x: .value("Month", $0.month), y: .value("Sales", $0.sales))
}
// CORRECT -- add per-mark accessibility
Chart(data) { item in
BarMark(x: .value("Month", item.month), y: .value("Sales", item.sales))
.accessibilityLabel("\(item.month)")
.accessibilityValue("\(item.sales) units sold")
}
9. Treating angle selection as category selection
chartAngleSelection(value:) binds the selected plottable angle value. For
pie and donut charts, map that numeric value through cumulative sector ranges
before comparing it to a category label.
Review Checklist
References
1---2name: swift-charts3description: Builds or reviews Swift Charts visualizations, including bar, line, area, point, sector, vectorized, and 3D charts. Use for marks, axes, scales, legends, annotations, selection, scrolling, styling, accessibility, large datasets, plots, or spatial surfaces.4---56# Swift Charts78Build data visualizations with Swift Charts targeting iOS 26+. Compose marks9inside `Chart` or `Chart3D`, configure axes and scales with view modifiers, and10use vectorized plots or 3D plots when the data calls for them.1112Use the task-specific chart references routed below instead of loading every recipe.1314## Contents1516- [Workflow](#workflow)17- [Route by Task](#route-by-task)18- [Core Decisions](#core-decisions)19- [Common Mistakes](#common-mistakes)20- [Review Checklist](#review-checklist)21- [References](#references)2223## Workflow24251. Identify the analytical question, data shape, deployment target, and accessibility requirement before choosing marks.262. Select the smallest mark set and encode series, categories, scales, and domains explicitly where ambiguity matters.273. Add axes, legends, annotations, selection, or scrolling only when they improve interpretation.284. Prefer vectorized plots or aggregation for large datasets and avoid expensive per-mark decoration.295. Verify empty/single/extreme data, localization, Dynamic Type, VoiceOver summaries, selection, and performance.3031## Route by Task3233- Read [core implementation details](references/core-implementation.md) for chart containers, marks, axes, scales, styles, selection, scrolling, annotations, vectorized plots, and 3D charts.34- Read [chart types and composition](references/chart-types-and-composition.md) for bars, lines, sectors, combined charts, and data modeling.35- Read [interaction, 3D, accessibility, and performance](references/interaction-3d-accessibility-and-performance.md) for selection, scrolling, function plots, surfaces, and large datasets.36- Read [styling, heat maps, and modifier reference](references/styling-heatmaps-and-reference.md) for themes, symbols, stacking, coordinate conversion, and quick-reference modifiers.3738## Core Decisions3940- Choose marks from the question being answered, not visual novelty.41- Preserve truthful scale domains and label units/aggregation clearly.42- Encode multiple line series with an explicit series dimension.43- Keep charts readable at large text sizes and expose nonvisual summaries.4445## Common Mistakes4647### 1. Missing series parameter for multi-line charts4849```swift50// WRONG -- all points connect into one line51Chart {52 ForEach(allCities) { item in53 LineMark(x: .value("Date", item.date), y: .value("Temp", item.temp))54 }55}5657// CORRECT -- separate lines per city58Chart {59 ForEach(allCities) { item in60 LineMark(x: .value("Date", item.date), y: .value("Temp", item.temp))61 .foregroundStyle(by: .value("City", item.city))62 }63}64```6566### 2. Too many SectorMark slices6768```swift69// WRONG -- 20 tiny sectors are unreadable70Chart(twentyCategories, id: \.name) { item in71 SectorMark(angle: .value("Value", item.value))72}7374// CORRECT -- group into top 5 + "Other"75Chart(groupedData, id: \.name) { item in76 SectorMark(angle: .value("Value", item.value))77 .foregroundStyle(by: .value("Category", item.name))78}79```8081### 3. Missing scale domain when zero-baseline matters8283```swift84// WRONG -- axis starts at ~95; small changes look dramatic85Chart(data) {86 LineMark(x: .value("Day", $0.day), y: .value("Score", $0.score))87}8889// CORRECT -- explicit domain for honest representation90Chart(data) {91 LineMark(x: .value("Day", $0.day), y: .value("Score", $0.score))92}93.chartYScale(domain: 0...100)94```9596### 4. Static foregroundStyle overriding data encoding9798```swift99// WRONG -- static color overrides by-value encoding100BarMark(x: .value("X", item.x), y: .value("Y", item.y))101 .foregroundStyle(by: .value("Category", item.category))102 .foregroundStyle(.blue)103104// CORRECT -- use only the data encoding105BarMark(x: .value("X", item.x), y: .value("Y", item.y))106 .foregroundStyle(by: .value("Category", item.category))107```108109### 5. Individual marks for 10,000+ data points110111```swift112// WRONG -- creates 10,000 mark views; slow113Chart(largeDataset) { item in114 PointMark(x: .value("X", item.x), y: .value("Y", item.y))115}116117// CORRECT -- vectorized plot (iOS 18+)118Chart {119 PointPlot(largeDataset, x: .value("X", \.x), y: .value("Y", \.y))120}121```122123### 6. Fixed chart height breaking Dynamic Type124125```swift126// WRONG -- clips axis labels at large text sizes127Chart(data) { ... }128 .frame(height: 200)129130// CORRECT -- adaptive sizing131Chart(data) { ... }132 .frame(minHeight: 200, maxHeight: 400)133```134135### 7. KeyPath modifier after value modifier on vectorized plots136137```swift138// WRONG -- compiler error139BarPlot(data, x: .value("X", \.x), y: .value("Y", \.y))140 .opacity(0.8)141 .foregroundStyle(\.color)142143// CORRECT -- KeyPath modifiers first144BarPlot(data, x: .value("X", \.x), y: .value("Y", \.y))145 .foregroundStyle(\.color)146 .opacity(0.8)147```148149### 8. Missing accessibility labels150151```swift152// WRONG -- VoiceOver users get no context153Chart(data) {154 BarMark(x: .value("Month", $0.month), y: .value("Sales", $0.sales))155}156157// CORRECT -- add per-mark accessibility158Chart(data) { item in159 BarMark(x: .value("Month", item.month), y: .value("Sales", item.sales))160 .accessibilityLabel("\(item.month)")161 .accessibilityValue("\(item.sales) units sold")162}163```164165### 9. Treating angle selection as category selection166167`chartAngleSelection(value:)` binds the selected plottable angle value. For168pie and donut charts, map that numeric value through cumulative sector ranges169before comparing it to a category label.170171## Review Checklist172173- [ ] Data model uses `Identifiable` or chart uses `id:` key path174- [ ] Mark type matches goal (bar=comparison, line=trend, sector=proportion)175- [ ] Multi-series lines use `series:` parameter or `.foregroundStyle(by:)`176- [ ] Axes configured with appropriate labels, ticks, and grid lines177- [ ] Scale domain set explicitly when zero-baseline matters178- [ ] Pie/donut uses positive values, 5-7 sectors, and "Other" grouping179- [ ] Selection binding type matches axis data type (`Date?` for date axis)180- [ ] Pie/donut angle selection maps numeric angle values back to categories181- [ ] Scrollable charts set `.chartXVisibleDomain(length:)` for viewport182- [ ] Vectorized plots used for datasets exceeding 1000 points183- [ ] KeyPath modifiers applied before value modifiers on vectorized plots184- [ ] `Chart3D` used only for real 3D data or surfaces, with z scale and pose reviewed185- [ ] Accessibility labels added to marks for VoiceOver186- [ ] Chart tested with Dynamic Type and Dark Mode187- [ ] Legend visible and positioned, or intentionally hidden188- [ ] Ensure chart data model types are Sendable; update chart data on @MainActor189190## References191192- [Chart types and composition](references/chart-types-and-composition.md)193- [Interaction, 3D, accessibility, and performance](references/interaction-3d-accessibility-and-performance.md)194- [Styling, heat maps, and modifier reference](references/styling-heatmaps-and-reference.md)195- Apple docs: [Swift Charts](https://sosumi.ai/documentation/charts)196- Apple docs: [Creating a chart using Swift Charts](https://sosumi.ai/documentation/charts/Creating-a-chart-using-Swift-Charts)197- Apple docs: [Swift Charts updates](https://sosumi.ai/documentation/updates/swiftcharts)198- Apple docs: [Chart3D](https://sosumi.ai/documentation/charts/Chart3D)199- Apple docs: [SurfacePlot](https://sosumi.ai/documentation/charts/SurfacePlot)200- [Core implementation details](references/core-implementation.md) -- setup, API wiring, and focused implementation recipes moved out of the entrypoint.