Building a bar chart
Using simple shapes, it is possible to build some nice features. For example, by just using a bunch of rectangles, we can create a bar chart.
In this recipe, we are going to create a bar chart that presents the average monthly precipitation for three European cities: Dublin, Milan, and London. The data that we'll use can be found at https://www.climatestotravel.com/.
Getting ready
This recipe doesn't need any external resources, so it's enough to create a SwiftUI project called BarChart
.
How to do it…
Based on information from https://www.climatestotravel.com/, the data we have represents the average quantity of rain in centimeters. Looking at the data, we can see that the maximum rainfall is 1 centimeter, so we can adapt the bars to have a full shape for that value.
To implement our bar chart, follow these steps:
- Add
enum
to represent the months and avalue type
datapoint to hold the values that will be plotted on...