1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// DemoListViewController.swift
// ChartsDemo-iOS
//
// Created by Jacob Christie on 2017-07-09.
// Copyright © 2017 jc. All rights reserved.
//
import UIKit
private struct ItemDef {
let title: String
let subtitle: String
let `class`: AnyClass
}
class DemoListViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private var itemDefs = [ItemDef(title: "Line Chart",
subtitle: "A simple demonstration of the linechart.",
class: LineChart1ViewController.self),
ItemDef(title: "Line Chart (Dual YAxis)",
subtitle: "Demonstration of the linechart with dual y-axis.",
class: LineChart2ViewController.self),
ItemDef(title: "Bar Chart",
subtitle: "A simple demonstration of the bar chart.",
class: BarChartViewController.self),
ItemDef(title: "Horizontal Bar Chart",
subtitle: "A simple demonstration of the horizontal bar chart.",
class: HorizontalBarChartViewController.self),
ItemDef(title: "Combined Chart",
subtitle: "Demonstrates how to create a combined chart (bar and line in this case).",
class: CombinedChartViewController.self),
ItemDef(title: "Pie Chart",
subtitle: "A simple demonstration of the pie chart.",
class: PieChartViewController.self),
ItemDef(title: "Pie Chart with value lines",
subtitle: "A simple demonstration of the pie chart with polyline notes.",
class: PiePolylineChartViewController.self),
ItemDef(title: "Scatter Chart",
subtitle: "A simple demonstration of the scatter chart.",
class: ScatterChartViewController.self),
ItemDef(title: "Bubble Chart",
subtitle: "A simple demonstration of the bubble chart.",
class: BubbleChartViewController.self),
ItemDef(title: "Stacked Bar Chart",
subtitle: "A simple demonstration of a bar chart with stacked bars.",
class: StackedBarChartViewController.self),
ItemDef(title: "Stacked Bar Chart Negative",
subtitle: "A simple demonstration of stacked bars with negative and positive values.",
class: NegativeStackedBarChartViewController.self),
ItemDef(title: "Another Bar Chart",
subtitle: "Implementation of a BarChart that only shows values at the bottom.",
class: AnotherBarChartViewController.self),
ItemDef(title: "Multiple Lines Chart",
subtitle: "A line chart with multiple DataSet objects. One color per DataSet.",
class: MultipleLinesChartViewController.self),
ItemDef(title: "Multiple Bars Chart",
subtitle: "A bar chart with multiple DataSet objects. One multiple colors per DataSet.",
class: MultipleBarChartViewController.self),
ItemDef(title: "Candle Stick Chart",
subtitle: "Demonstrates usage of the CandleStickChart.",
class: CandleStickChartViewController.self),
ItemDef(title: "Cubic Line Chart",
subtitle: "Demonstrates cubic lines in a LineChart.",
class: CubicLineChartViewController.self),
ItemDef(title: "Radar Chart",
subtitle: "Demonstrates the use of a spider-web like (net) chart.",
class: RadarChartViewController.self),
ItemDef(title: "Colored Line Chart",
subtitle: "Shows a LineChart with different background and line color.",
class: ColoredLineChartViewController.self),
ItemDef(title: "Sinus Bar Chart",
subtitle: "A Bar Chart plotting the sinus function with 8.000 values.",
class: SinusBarChartViewController.self),
ItemDef(title: "BarChart positive / negative",
subtitle: "This demonstrates how to create a BarChart with positive and negative values in different colors.",
class: PositiveNegativeBarChartViewController.self),
ItemDef(title: "Time Line Chart",
subtitle: "Simple demonstration of a time-chart. This chart draws one line entry per hour originating from the current time in milliseconds.",
class: LineChartTimeViewController.self),
ItemDef(title: "Filled Line Chart",
subtitle: "This demonstrates how to fill an area between two LineDataSets.",
class: LineChartFilledViewController.self),
ItemDef(title: "Half Pie Chart",
subtitle: "This demonstrates how to create a 180 degree PieChart.",
class: HalfPieChartViewController.self)
]
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Charts Demonstration"
self.tableView.rowHeight = 70
//FIXME: Add TimeLineChart
}
}
extension DemoListViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.itemDefs.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let def = self.itemDefs[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style: .subtitle, reuseIdentifier: "Cell")
cell.textLabel?.text = def.title
cell.detailTextLabel?.text = def.subtitle
cell.detailTextLabel?.numberOfLines = 0
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let def = self.itemDefs[indexPath.row]
let vcClass = def.class as! UIViewController.Type
let vc = vcClass.init()
self.navigationController?.pushViewController(vc, animated: true)
tableView.deselectRow(at: indexPath, animated: true)
}
}