-
-
Save sturdysturge/a422c1ec798ac1eef778afcf4147e300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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