Building a bar chart
Using simple shapes, it is possible to build some nice features. For example, using just a bunch of rectangles, we can create a nice bar chart.
We are going to present the average monthly precipitation for three European cities: Dublin, Milan, and London. The data that we'll use is from https://www.climatestotravel.com/.
Getting ready
This recipe doesn't need any external resources, so it's enough to create a SwiftUI project called BarChartApp
.
How to do it...
The data we have represents the average quantity of rain in centimeters. Looking at the data, we can see that the maximum rainfall is one centimeter, so we can adapt the bars to have a full shape for that value.
Let's implement our bar chart as follows:
- Add
enum
to represent the months and a datapoint value type to hold the values to plot on the bar chart:enum Month: String, CaseIterable { case jan, feb, mar, apr, may, jun, ...