Understanding the basics of Swift Charts
In this recipe, we are going to introduce the basic building blocks of Swift Charts. We will create some charts to display the results of a hypothetical survey, conducted with a questionnaire, in a graphical way. We will start with a simple chart displaying the number of answers for each question, and then add a couple of detailed charts, to see the different answers to each question.
Getting ready
Create a new SwiftUI iOS app named SwiftChartsBasics
.
How to do it…
Our app will have just one view, which will include the charts. We will also have a data layer in a separate file. Let’s start working on the data first, and then switch to the view. These are the steps:
- Create a new Swift file named
SurveyEntry.swift
. This file will contain our data layer. Start by creating a couple ofString
enumerations with implicitly assigned raw values, one to model our questions and one to model the answers: ...