Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Reviews, improves, and writes SwiftUI code following state management, view composition, performance, and iOS 26+ Liquid Glass best practices.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/charts-accessibility.md
1# Swift Charts Accessibility, Fallback, and Resources23## Table of Contents45- [Accessibility](#accessibility)6- [Meaningful Labels](#meaningful-labels)7- [Custom Audio Graphs](#custom-audio-graphs)8- [Composite Example](#composite-example)9- [Fallback Strategies](#fallback-strategies)10- [Version Breakdown](#version-breakdown)11- [WWDC Sessions](#wwdc-sessions)12- [Summary Checklist](#summary-checklist)1314---1516## Accessibility1718Swift Charts provides built-in accessibility support. VoiceOver users get three rotor actions automatically:1920- **Describe Chart** — overview of axes and data series21- **Audio Graph** — sonification where pitch represents data values22- **Chart Detail** — interactive mode for exploring individual data points2324### Meaningful Labels2526**Always** use clear, descriptive strings in `.value(_, _)` calls. These labels are read by VoiceOver and used in the Audio Graph.2728```swift29// Good — descriptive labels30LineMark(31x: .value("Date", entry.date),32y: .value("Daily Steps", entry.count)33)3435// Bad — generic labels36LineMark(37x: .value("X", entry.date),38y: .value("Y", entry.count)39)40```4142### Custom Audio Graphs4344For advanced accessibility, conform your chart view to `AXChartDescriptorRepresentable` and implement `makeChartDescriptor()`. Attach it with `.accessibilityChartDescriptor(self)`.4546```swift47struct StepsChart: View, AXChartDescriptorRepresentable {48let steps: [DailySteps]4950var body: some View {51Chart(steps) { day in52LineMark(x: .value("Date", day.date), y: .value("Steps", day.count))53}54.accessibilityChartDescriptor(self)55}5657func makeChartDescriptor() -> AXChartDescriptor {58guard let first = steps.first, let last = steps.last else {59return AXChartDescriptor(title: "Daily Step Count", summary: nil,60xAxis: AXNumericDataAxisDescriptor(title: "Date", range: 0...1, gridlinePositions: []) { "\($0)" },61yAxis: AXNumericDataAxisDescriptor(title: "Steps", range: 0...1, gridlinePositions: []) { "\($0)" },62additionalAxes: [], series: [])63}64let xAxis = AXDateDataAxisDescriptor(65title: "Date", range: first.date...last.date, gridlinePositions: [])66let yAxis = AXNumericDataAxisDescriptor(67title: "Steps", range: 0...Double(steps.map(\.count).max() ?? 0),68gridlinePositions: []) { "\(Int($0)) steps" }69let series = AXDataSeriesDescriptor(70name: "Daily Steps", isContinuous: true,71dataPoints: steps.map { .init(x: $0.date, y: Double($0.count)) })72return AXChartDescriptor(title: "Daily Step Count", summary: nil,73xAxis: xAxis, yAxis: yAxis, additionalAxes: [], series: [series])74}75}76```7778## Composite Example7980A scrollable bar chart with range selection combining multiple iOS 17+ APIs:8182```swift83@State private var selectedRange: ClosedRange<Int>?8485Chart(weeklyRevenue) { week in86BarMark(x: .value("Week", week.index), y: .value("Revenue", week.revenue))87.foregroundStyle(by: .value("Region", week.region))88}89.chartScrollableAxes(.horizontal)90.chartXVisibleDomain(length: 8)91.chartXSelection(range: $selectedRange)92.chartXAxis {93AxisMarks(values: .stride(by: 1)) {94AxisGridLine()95AxisValueLabel { Text("W\($0.as(Int.self) ?? 0)") }96}97}98```99100## Fallback Strategies101102Gate advanced APIs with `#available` and provide a fallback chart without the gated features. Because chart modifiers like `.chartXSelection` change the return type, you must duplicate the entire `Chart` — you cannot conditionally apply the modifier:103104### Version Breakdown105106- iOS 16+: `Chart`, custom axes, scales, `BarMark`, `LineMark`, `AreaMark`, `PointMark`, `RectangleMark`, `RuleMark`, `ChartProxy`, `chartOverlay`, `chartBackground`107- iOS 17+: `SectorMark`, `chartXSelection`, `chartYSelection`, `chartAngleSelection`, `chartScrollableAxes`, visible-domain scrolling APIs, `chartGesture`108- iOS 18+: `AreaPlot`, `BarPlot`, `LinePlot`, `PointPlot`, `RectanglePlot`, `RulePlot`, `SectorPlot`, function plotting109- iOS 26+: `Chart3D`, `SurfacePlot`, Z-axis marks, 3D camera and pose APIs110111## WWDC Sessions112113- [Hello Swift Charts](https://developer.apple.com/videos/play/wwdc2022/10136/) (WWDC 2022) — introduction to the framework114- [Swift Charts: Raise the bar](https://developer.apple.com/videos/play/wwdc2022/10137/) (WWDC 2022) — marks, composition, customization115- [Design an effective chart](https://developer.apple.com/videos/play/wwdc2022/110340/) (WWDC 2022) — chart design principles116- [Design app experiences with charts](https://developer.apple.com/videos/play/wwdc2022/110342/) (WWDC 2022) — integrating charts into app UX117- [Explore pie charts and interactivity in Swift Charts](https://developer.apple.com/videos/play/wwdc2023/10037/) (WWDC 2023) — SectorMark, selection, scrolling118- [Swift Charts: Vectorized and function plots](https://developer.apple.com/videos/play/wwdc2024/10155/) (WWDC 2024) — LinePlot, AreaPlot, function plotting119- [Bring Swift Charts to the third dimension](https://developer.apple.com/videos/play/wwdc2025/313/) (WWDC 2025) — Chart3D, SurfacePlot, 3D marks120121## Summary Checklist122123- [ ] `import Charts` is present in files using chart types124- [ ] Deployment target matches the APIs used (`Chart` on iOS 16+, selection and `SectorMark` on iOS 17+, plot types on iOS 18+, `Chart3D` on iOS 26+)125- [ ] Chart data models use `Identifiable` (or `Chart(data, id:)` is provided)126- [ ] All chart families are represented with the correct mark type127- [ ] Axes use `AxisMarks` when default ticks are too dense or unclear128- [ ] `chartXScale` or `chartYScale` is set when fixed domains matter129- [ ] Chart-wide modifiers are applied to `Chart`, not individual marks130- [ ] `foregroundStyle(by:)` used for categorical series (not manual per-mark colors)131- [ ] Single-value selection uses `chartXSelection(value:)` or `chartYSelection(value:)`132- [ ] Range selection uses `chartXSelection(range:)` or `chartYSelection(range:)`133- [ ] `SectorMark` selection uses `chartAngleSelection(value:)`134- [ ] iOS 17+, iOS 18+, and iOS 26+ APIs are guarded with `#available`135- [ ] `.value()` labels are descriptive for VoiceOver and Audio Graph accessibility136