Skip to content

Instantly share code, notes, and snippets.

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 SahilMutualMobile/d4e1d4e24444db09133cee2f972853bf to your computer and use it in GitHub Desktop.
Save SahilMutualMobile/d4e1d4e24444db09133cee2f972853bf to your computer and use it in GitHub Desktop.
SwiftChart_Pickers
import SwiftUI
import Charts
struct ContentView: View {
@State var timing: TimingType = .Morning
@State var chartType: ChartType = .Barchart
var data: [RestaurantSales] {
switch timing {
case .Morning:
return morningSales
case .Evening:
return eveningSales
}
}
var body: some View {
VStack(alignment:.leading) {
Text("Select Chart")
.font(.headline)
.fontWeight(.bold)
Picker("Select chart", selection: $chartType.animation(.easeIn)) {
Text("Bar").tag(ChartType.Barchart)
Text("Line").tag(ChartType.Linechart)
Text("Point").tag(ChartType.Pointchart)
Text("Area").tag(ChartType.Areachart)
Text("Rule").tag(ChartType.Rulechart)
Text("Rect").tag(ChartType.Rectanglechart)
}
.pickerStyle(.segmented)
Text("Sip n Snacks")
.font(.headline)
.fontWeight(.bold)
.padding(.top)
Text("Sales analysis")
.font(.subheadline)
.fontWeight(.medium)
Picker("Timing", selection: $timing.animation(.easeIn)) {
Text("Morning").tag(TimingType.Morning)
Text("Evening").tag(TimingType.Evening)
}
.pickerStyle(.segmented)
switch chartType {
case .Barchart:
Barchart(timing: $timing, data: data)
case .Linechart:
Linechart(timing: $timing, data: data)
case .Pointchart:
Pointchart(timing: $timing, data: data)
case .Areachart:
Areachart(timing: $timing, data: data)
case .Rulechart:
Rulechart(timing: $timing, data: data)
case .Rectanglechart:
Rectanglechart(timing: $timing, data: data)
}
Spacer()
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment