Skip to content

Instantly share code, notes, and snippets.

View navsing's full-sized avatar
🏠
Working from home

Navdeep Singh navsing

🏠
Working from home
View GitHub Profile
struct chartData: Identifiable {
var id = 0
var year: String
var awards: Double
}
//adding placeholderdata
var data: [chartData] = [
chartData(year: "2000", awards: 100),
chartData(year: "2005", awards: 200),
//Base Components
Chart(data) { i in
LineMark(
x: .value("x-axis", i.year),
y: .value("y-axis", i.awards)
)
}
//Customization to try on the line component
.lineStyle(StrokeStyle(lineWidth: 2)) // add stroke to the line
.foregroundStyle(.blue) // add color to the line
//Base Component
BarMark(
x: .value("Year", i.year),
y: .value("Awards", i.awards)
)
//Customization to try
RuleMark(y: .value("rulemark", 275)).foregroundStyle(.red) //adds a rule mark
//add multiple data sources for stacked charts. See Image.
//create 1-D charts
.chartPlotStyle { area in
AreaMark(
x: .value("Year", i.year),
y: .value("Awards", i.awards)
).foregroundStyle(.blue)
.interpolationMethod(.cardinal)
//Use multiple sources to create stacked area charts - add the code below
AreaMark(
x: .value("Year", i.year),
import Combine
import SwiftUI
struct ImageViewController: View {
@ObservedObject var url: LoadUrlImage
init(imageUrl: String) {
url = LoadUrlImage(imageURL: imageUrl)
}
var body: some View {