Hello Swift Charts

Written by Cihat Gündüz

Description: Say hello to Swift Charts — a flexible framework that helps you create charts entirely in SwiftUI that look and feel right at home on all Apple platforms. Discover how you can use compositional syntax to make informative, delightful, and accessible charts with less code. We’ll share the building blocks for making visualizations with Swift Charts, and explore how you can change your charts’ design with a simple modifier. We’ll also take you through the latest updates to Xcode Previews to help you chart a path toward an engaging experience.

  • Declarative, Compositional, like SwiftUI
  • requires import Charts to use

Chart

  • Chart is the main outside wrapper
  • BarMark with x and y positions and .value data
  • first argument of value is description, second the value
  • make data types Identifiable to use in Charts
  • supports ForEach for Identifiable data collections
  • Implicit forEach via a Chart initializer taking a data collection
  • Charts chooses an appropriate visualization automatically
  • Adapts to dynamic type, device sizes, orientations, dark mode and supports accessibility automatically

Features

  • When navigation charts in VoiceOver speaks the description + value
  • Supports AudioGraph feature from 2021, too (peep sounds)
  • .value also accepts a unit for types like Date, e.g. .day
  • Supports SwiftUI animations (e.g. animate between different data collections but same bar chart view)
  • Use .foregroundStyle(by: to group data by color → auto-generated legend for the colors
  • Easy to change from BarMark to PointMark or LineMark (great for prototyping charts!)
  • Also .symbol(by: a value available to use square/circle instead of color to differentiate data form each other
  • Marks: Bar, Point, Line
  • Mark Properties: X Position, Y Position, Foreground Style, Symbol
  • More Marks available: Area, Rule, Rectangle
  • More Mark Properties available: Symbol Size, Line Style
  • Support for:
    • Dark Mode
    • Device Screen Sizes
    • Dynamic Type
    • Voice Over
    • Audio Graphs
    • High-Contrast
    • Localization
    • Multi-Platform

Missing anything? Corrections? Contributions are welcome 😃

Related

Written by

Cihat Gündüz

Cihat Gündüz

📱Indie iOS Developer, 🎬Content Creator for 👨🏻‍💻Developers. 👾Twitch-Streamer & ▶️YouTuber.