Created
September 4, 2022 20:47
-
-
Save SahilMutualMobile/d4e1d4e24444db09133cee2f972853bf to your computer and use it in GitHub Desktop.
SwiftChart_Pickers
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 | |
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