Exploring chart marks and modifiers
Now that we’ve accomplished plugging data into Swift Charts, it’s time to learn how we can alter how our chart displays our data. The two most significant ways we can alter the look of our chart are through marks and modifiers. When combined, there are countless ways we can alter the look (and feel) of a chart.
How to do it...
We will start where we left off in our previous project:
- In
CoffeePerformance.swift
, let’s add a smallenum
of the marks we will be exploring:enum ChartMark {
case bar, line, area, point, rect
}
- In
CoffeePerformance
(the View itself), we’ll place a newState
:@State var selectedChartMark: ChartMark = .bar
- We’re going to replace
BarMark
and expand it with a switch over all the different types ofMark
:switch selectedChartMark {
case .bar:
BarMark(
x: .value("Cups of Coffee"...