New in SwiftUI 4: Stacked Bar Chart

DevTechie
DevTechie
Published in
3 min readJun 12, 2022

--

Stacked Bar Charts are used when we want to show comparisons between categories. Typically, the bars are proportional to the values they represent and can be plotted either horizontally or vertically. One axis of the chart shows the specific categories being compared, and the other axis represents discrete values.

Today, we will build a stacked bar chart using Apple’s newly introduced Charts Framework in SwiftUI 4 with iOS 16. If you want to learn more about Charts, please checkout a detailed article here: https://medium.com/devtechie/new-in-swiftui-4-charts-bar-chart-f242698b04f4

We will start with a data structure for our example. In this example, we will plot DevTechie’s courses, platforms where courses are published and number of students in each platform.

Let’s start with an enum for course category and source:

enum DTCourseCategory: String {
case uIKit = "UIKit"
case swiftUI = "SwiftUI"
case machineLearning = "Machine Learning"
}
enum DTCourseSource: String {
case youTube = "YouTube"
case devTechie = "DevTechie.com"
case udemy = "Udemy"
case medium = "Medium"
}

Next, we will create DevTechieCourses struct and add some sample data:

struct DevTechieCourses: Identifiable {
let id = UUID()
let…

--

--