Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created July 31, 2022 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/a422c1ec798ac1eef778afcf4147e300 to your computer and use it in GitHub Desktop.
Save sturdysturge/a422c1ec798ac1eef778afcf4147e300 to your computer and use it in GitHub Desktop.
import SwiftUI
import Charts
@available(iOS 16, *)
struct ContentView: View {
let data: [TipData] = [TipData(value: 96, title: .tip), TipData(value: 24, title: .noTip)]
var body: some View {
Chart(data) { value in
// Stacked Bar
BarMark(
x: .value("Value", value.value),
y: .value("Title", DataTitle.all.rawValue)
)
.annotation(position: .overlay) {
Text(String(format: "%.f", value.value))
.modifier(AnnotationViewModifier())
}
.foregroundStyle(by: .value("Category", value.title.rawValue))
// Regular Bars
BarMark(
x: .value("Value", value.value),
y: .value("Title", value.title.rawValue)
)
.annotation(position: .overlay) {
Text(String(format: "%.f", value.value))
.modifier(AnnotationViewModifier())
}
.foregroundStyle(by: .value("Category", value.title.rawValue))
}
.padding()
.frame(height: 300)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment