DemoListViewController.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // DemoListViewController.m
  3. // ChartsDemo
  4. //
  5. // Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
  6. // A port of MPAndroidChart for iOS
  7. // Licensed under Apache License 2.0
  8. //
  9. // https://github.com/danielgindi/Charts
  10. //
  11. #import "DemoListViewController.h"
  12. #import "LineChart1ViewController.h"
  13. #import "LineChart2ViewController.h"
  14. #import "BarChartViewController.h"
  15. #import "HorizontalBarChartViewController.h"
  16. #import "CombinedChartViewController.h"
  17. #import "PieChartViewController.h"
  18. #import "PiePolylineChartViewController.h"
  19. #import "ScatterChartViewController.h"
  20. #import "StackedBarChartViewController.h"
  21. #import "NegativeStackedBarChartViewController.h"
  22. #import "AnotherBarChartViewController.h"
  23. #import "MultipleLinesChartViewController.h"
  24. #import "MultipleBarChartViewController.h"
  25. #import "CandleStickChartViewController.h"
  26. #import "CubicLineChartViewController.h"
  27. #import "RadarChartViewController.h"
  28. #import "ColoredLineChartViewController.h"
  29. #import "SinusBarChartViewController.h"
  30. #import "PositiveNegativeBarChartViewController.h"
  31. #import "BubbleChartViewController.h"
  32. #import "LineChartTimeViewController.h"
  33. #import "LineChartFilledViewController.h"
  34. #import "HalfPieChartViewController.h"
  35. @interface DemoListViewController () <UITableViewDataSource, UITableViewDelegate>
  36. @property (nonatomic, strong) IBOutlet UITableView *tableView;
  37. @property (nonatomic, strong) NSArray *itemDefs;
  38. @end
  39. @implementation DemoListViewController
  40. - (void)viewDidLoad
  41. {
  42. [super viewDidLoad];
  43. self.title = @"Charts Demonstration";
  44. self.itemDefs = @[
  45. @{
  46. @"title": @"Line Chart",
  47. @"subtitle": @"A simple demonstration of the linechart.",
  48. @"class": LineChart1ViewController.class
  49. },
  50. @{
  51. @"title": @"Line Chart (Dual YAxis)",
  52. @"subtitle": @"Demonstration of the linechart with dual y-axis.",
  53. @"class": LineChart2ViewController.class
  54. },
  55. @{
  56. @"title": @"Bar Chart",
  57. @"subtitle": @"A simple demonstration of the bar chart.",
  58. @"class": BarChartViewController.class
  59. },
  60. @{
  61. @"title": @"Horizontal Bar Chart",
  62. @"subtitle": @"A simple demonstration of the horizontal bar chart.",
  63. @"class": HorizontalBarChartViewController.class
  64. },
  65. @{
  66. @"title": @"Combined Chart",
  67. @"subtitle": @"Demonstrates how to create a combined chart (bar and line in this case).",
  68. @"class": CombinedChartViewController.class
  69. },
  70. @{
  71. @"title": @"Pie Chart",
  72. @"subtitle": @"A simple demonstration of the pie chart.",
  73. @"class": PieChartViewController.class
  74. },
  75. @{
  76. @"title": @"Pie Chart with value lines",
  77. @"subtitle": @"A simple demonstration of the pie chart with polyline notes.",
  78. @"class": PiePolylineChartViewController.class
  79. },
  80. @{
  81. @"title": @"Scatter Chart",
  82. @"subtitle": @"A simple demonstration of the scatter chart.",
  83. @"class": ScatterChartViewController.class
  84. },
  85. @{
  86. @"title": @"Bubble Chart",
  87. @"subtitle": @"A simple demonstration of the bubble chart.",
  88. @"class": BubbleChartViewController.class
  89. },
  90. @{
  91. @"title": @"Stacked Bar Chart",
  92. @"subtitle": @"A simple demonstration of a bar chart with stacked bars.",
  93. @"class": StackedBarChartViewController.class
  94. },
  95. @{
  96. @"title": @"Stacked Bar Chart Negative",
  97. @"subtitle": @"A simple demonstration of stacked bars with negative and positive values.",
  98. @"class": NegativeStackedBarChartViewController.class
  99. },
  100. @{
  101. @"title": @"Another Bar Chart",
  102. @"subtitle": @"Implementation of a BarChart that only shows values at the bottom.",
  103. @"class": AnotherBarChartViewController.class
  104. },
  105. @{
  106. @"title": @"Multiple Lines Chart",
  107. @"subtitle": @"A line chart with multiple DataSet objects. One color per DataSet.",
  108. @"class": MultipleLinesChartViewController.class
  109. },
  110. @{
  111. @"title": @"Multiple Bars Chart",
  112. @"subtitle": @"A bar chart with multiple DataSet objects. One multiple colors per DataSet.",
  113. @"class": MultipleBarChartViewController.class
  114. },
  115. @{
  116. @"title": @"Candle Stick Chart",
  117. @"subtitle": @"Demonstrates usage of the CandleStickChart.",
  118. @"class": CandleStickChartViewController.class
  119. },
  120. @{
  121. @"title": @"Cubic Line Chart",
  122. @"subtitle": @"Demonstrates cubic lines in a LineChart.",
  123. @"class": CubicLineChartViewController.class
  124. },
  125. @{
  126. @"title": @"Radar Chart",
  127. @"subtitle": @"Demonstrates the use of a spider-web like (net) chart.",
  128. @"class": RadarChartViewController.class
  129. },
  130. @{
  131. @"title": @"Colored Line Chart",
  132. @"subtitle": @"Shows a LineChart with different background and line color.",
  133. @"class": ColoredLineChartViewController.class
  134. },
  135. @{
  136. @"title": @"Sinus Bar Chart",
  137. @"subtitle": @"A Bar Chart plotting the sinus function with 8.000 values.",
  138. @"class": SinusBarChartViewController.class
  139. },
  140. @{
  141. @"title": @"BarChart positive / negative",
  142. @"subtitle": @"This demonstrates how to create a BarChart with positive and negative values in different colors.",
  143. @"class": PositiveNegativeBarChartViewController.class
  144. },
  145. @{
  146. @"title": @"Time Line Chart",
  147. @"subtitle": @"Simple demonstration of a time-chart. This chart draws one line entry per hour originating from the current time in milliseconds.",
  148. @"class": LineChartTimeViewController.class
  149. },
  150. @{
  151. @"title": @"Filled Line Chart",
  152. @"subtitle": @"This demonstrates how to fill an area between two LineDataSets.",
  153. @"class": LineChartFilledViewController.class
  154. },
  155. @{
  156. @"title": @"Half Pie Chart",
  157. @"subtitle": @"This demonstrates how to create a 180 degree PieChart.",
  158. @"class": HalfPieChartViewController.class
  159. }
  160. ];
  161. //FIXME: Add TimeLineChart
  162. }
  163. - (void)didReceiveMemoryWarning
  164. {
  165. [super didReceiveMemoryWarning];
  166. // Dispose of any resources that can be recreated.
  167. }
  168. #pragma mark - UITableViewDataSource, UITableViewDelegate
  169. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  170. {
  171. return 1;
  172. }
  173. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  174. {
  175. return self.itemDefs.count;
  176. }
  177. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  178. {
  179. return 70.f;
  180. }
  181. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  182. {
  183. NSDictionary *def = self.itemDefs[indexPath.row];
  184. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
  185. if (!cell)
  186. {
  187. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
  188. }
  189. cell.textLabel.text = def[@"title"];
  190. cell.detailTextLabel.text = def[@"subtitle"];
  191. cell.detailTextLabel.numberOfLines = 0;
  192. return cell;
  193. }
  194. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  195. {
  196. NSDictionary *def = self.itemDefs[indexPath.row];
  197. Class vcClass = def[@"class"];
  198. UIViewController *vc = [[vcClass alloc] init];
  199. [self.navigationController pushViewController:vc animated:YES];
  200. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  201. }
  202. @end