Last active
May 2, 2020 18:59
John James demonstrated using SwiftUI charts
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
// Load the Swift Package: https://github.com/AppPear/ChartView | |
import SwiftUI | |
import SwiftUICharts | |
struct ContentView: View { | |
@State var tabIndex:Int = 0 | |
var body: some View { | |
TabView(selection: $tabIndex) { | |
BarCharts().tabItem { Group{ | |
Image(systemName: "chart.bar") | |
Text("Bar charts") | |
}}.tag(0) | |
LineCharts().tabItem { Group{ | |
Image(systemName: "waveform.path.ecg") | |
Text("Line charts") | |
}}.tag(1) | |
PieCharts().tabItem { Group{ | |
Image(systemName: "chart.pie") | |
Text("Pie charts") | |
}}.tag(2) | |
LineChartsFull().tabItem { Group{ | |
Image(systemName: "waveform.path.ecg") | |
Text("Full screen line charts") | |
}}.tag(3) | |
} | |
} | |
} | |
struct BarCharts:View { | |
var body: some View { | |
VStack{ | |
BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", style: Styles.barChartStyleOrangeLight) | |
} | |
} | |
} | |
struct LineCharts:View { | |
var body: some View { | |
VStack{ | |
LineChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title") | |
} | |
} | |
} | |
struct PieCharts:View { | |
var body: some View { | |
VStack{ | |
PieChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title") | |
} | |
} | |
} | |
struct LineChartsFull: View { | |
var body: some View { | |
VStack{ | |
LineView(data: [8,23,54,32,12,37,7,23,43], title: "Line chart", legend: "Full screen").padding() | |
// legend is optional, use optional .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