Building a chart with data
In this first recipe, we’re going to create a simple Swift Chart that will help us visualize work performance based on the cups of coffee they’ve had (scientific accuracy questionable). We’ll do this in a barebones SwiftUI app.
Getting ready
For all the recipes in this chapter, you’ll need the latest version of Xcode available from the Mac App Store.
How to do it…
With Xcode open, let’s get started:
- Create a new project in Xcode. Go to File | New | Project | iOS App. Be sure to choose SwiftUI for the interface.
- In our project, select New File | SwiftUI View, and name this file
CoffeePerformance
. - In our new file, the first thing is to add Swift Charts by adding
import Charts
to the top of our file. - Let’s create some data for our chart to consume. First, make a new struct called
PerformanceInfo
:struct PerformanceInfo: Identifiable {
var cups: Int
...