Customizing charts: axes, annotations, and rules
In this recipe, we are going to learn how to customize a chart to make it look more appealing. We will use a bar chart to plot the average rainfall for the city of Austin, TX, for each month of the year 2022. We will use the x-axis to plot the month, and the y-axis to plot the quantity. We will customize the axis scales, labels, and gridlines, add custom annotations to the bars, and add a rule with custom text. To make it more convenient for the user, we will introduce a control to switch between European units (millimeters) and US units (inches).
Getting ready
Create a new SwiftUI iOS app named ChartCustomizations
.
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:
- Drag and drop the
climate_data.json
file from the book’...