Showing
3 changed files
with
91 additions
and
43 deletions
| @@ -7,8 +7,12 @@ | @@ -7,8 +7,12 @@ | ||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | +#import "PNChartDelegate.h" | ||
| 11 | +#import "PNChart.h" | ||
| 10 | 12 | ||
| 11 | -@interface PCChartViewController : UIViewController | 13 | +@interface PCChartViewController : UIViewController<PNChartDelegate> |
| 14 | + | ||
| 15 | +@property (nonatomic) PNLineChart * lineChart; | ||
| 12 | - (IBAction)changeValue:(id)sender; | 16 | - (IBAction)changeValue:(id)sender; |
| 13 | 17 | ||
| 14 | @end | 18 | @end |
| @@ -10,8 +10,93 @@ | @@ -10,8 +10,93 @@ | ||
| 10 | 10 | ||
| 11 | @implementation PCChartViewController | 11 | @implementation PCChartViewController |
| 12 | 12 | ||
| 13 | + | ||
| 14 | +-(void)viewDidLoad | ||
| 15 | +{ | ||
| 16 | + [super viewDidLoad]; | ||
| 17 | + | ||
| 18 | + if ([self.title isEqualToString:@"Line Chart"]) { | ||
| 19 | + UILabel * lineChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)]; | ||
| 20 | + lineChartLabel.text = @"Line Chart"; | ||
| 21 | + lineChartLabel.textColor = PNFreshGreen; | ||
| 22 | + lineChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0]; | ||
| 23 | + lineChartLabel.textAlignment = NSTextAlignmentCenter; | ||
| 24 | + | ||
| 25 | + self.lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; | ||
| 26 | + self.lineChart.yLabelFormat = @"%1.1f"; | ||
| 27 | + self.lineChart.backgroundColor = [UIColor clearColor]; | ||
| 28 | + [self.lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]]; | ||
| 29 | + self.lineChart.showCoordinateAxis = YES; | ||
| 30 | + | ||
| 31 | + // Line Chart #1 | ||
| 32 | + NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2]; | ||
| 33 | + PNLineChartData *data01 = [PNLineChartData new]; | ||
| 34 | + data01.color = PNFreshGreen; | ||
| 35 | + data01.itemCount = data01Array.count; | ||
| 36 | + data01.inflexionPointStyle = PNLineChartPointStyleTriangle; | ||
| 37 | + data01.getData = ^(NSUInteger index) { | ||
| 38 | + CGFloat yValue = [data01Array[index] floatValue]; | ||
| 39 | + return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 40 | + }; | ||
| 41 | + | ||
| 42 | + // Line Chart #2 | ||
| 43 | + NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2]; | ||
| 44 | + PNLineChartData *data02 = [PNLineChartData new]; | ||
| 45 | + data02.color = PNTwitterColor; | ||
| 46 | + data02.itemCount = data02Array.count; | ||
| 47 | + data02.inflexionPointStyle = PNLineChartPointStyleSquare; | ||
| 48 | + data02.getData = ^(NSUInteger index) { | ||
| 49 | + CGFloat yValue = [data02Array[index] floatValue]; | ||
| 50 | + return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 51 | + }; | ||
| 52 | + | ||
| 53 | + self.lineChart.chartData = @[data01, data02]; | ||
| 54 | + [self.lineChart strokeChart]; | ||
| 55 | + | ||
| 56 | + self.lineChart.delegate = self; | ||
| 57 | + | ||
| 58 | + [self.view addSubview:lineChartLabel]; | ||
| 59 | + [self.view addSubview:self.lineChart]; | ||
| 60 | + } | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex{ | ||
| 65 | + NSLog(@"Click Key on line %f, %f line index is %d and point index is %d",point.x, point.y,(int)lineIndex, (int)pointIndex); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex{ | ||
| 69 | + NSLog(@"Click on line %f, %f, line index is %d",point.x, point.y, (int)lineIndex); | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | + | ||
| 13 | - (IBAction)changeValue:(id)sender { | 73 | - (IBAction)changeValue:(id)sender { |
| 14 | - if ([self.title isEqualToString:@"Bar Chart"]) { | 74 | + if ([self.title isEqualToString:@"Line Chart"]) { |
| 75 | + | ||
| 76 | + | ||
| 77 | + // Line Chart #1 | ||
| 78 | + NSArray * data01Array = @[@30.1, @20.1, @106.4, @162.2, @86.2, @27.2, @76.2]; | ||
| 79 | + PNLineChartData *data01 = [PNLineChartData new]; | ||
| 80 | + data01.color = PNFreshGreen; | ||
| 81 | + data01.itemCount = data01Array.count; | ||
| 82 | + data01.inflexionPointStyle = PNLineChartPointStyleTriangle; | ||
| 83 | + data01.getData = ^(NSUInteger index) { | ||
| 84 | + CGFloat yValue = [data01Array[index] floatValue]; | ||
| 85 | + return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 86 | + }; | ||
| 87 | + | ||
| 88 | + // Line Chart #2 | ||
| 89 | + NSArray * data02Array = @[@60.1, @120.1, @126.4, @102.2, @26.2, @67.2, @176.2]; | ||
| 90 | + PNLineChartData *data02 = [PNLineChartData new]; | ||
| 91 | + data02.color = PNTwitterColor; | ||
| 92 | + data02.itemCount = data02Array.count; | ||
| 93 | + data02.inflexionPointStyle = PNLineChartPointStyleSquare; | ||
| 94 | + data02.getData = ^(NSUInteger index) { | ||
| 95 | + CGFloat yValue = [data02Array[index] floatValue]; | ||
| 96 | + return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 97 | + }; | ||
| 98 | + | ||
| 99 | + [self.lineChart updateChartData:@[data01, data02]]; | ||
| 15 | 100 | ||
| 16 | } | 101 | } |
| 17 | } | 102 | } |
| @@ -21,47 +21,6 @@ | @@ -21,47 +21,6 @@ | ||
| 21 | if ([segue.identifier isEqualToString:@"lineChart"]) { | 21 | if ([segue.identifier isEqualToString:@"lineChart"]) { |
| 22 | 22 | ||
| 23 | //Add line chart | 23 | //Add line chart |
| 24 | - UILabel * lineChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)]; | ||
| 25 | - lineChartLabel.text = @"Line Chart"; | ||
| 26 | - lineChartLabel.textColor = PNFreshGreen; | ||
| 27 | - lineChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0]; | ||
| 28 | - lineChartLabel.textAlignment = NSTextAlignmentCenter; | ||
| 29 | - | ||
| 30 | - PNLineChart * lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; | ||
| 31 | - lineChart.yLabelFormat = @"%1.1f"; | ||
| 32 | - lineChart.backgroundColor = [UIColor clearColor]; | ||
| 33 | - [lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]]; | ||
| 34 | - lineChart.showCoordinateAxis = YES; | ||
| 35 | - | ||
| 36 | - // Line Chart #1 | ||
| 37 | - NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2]; | ||
| 38 | - PNLineChartData *data01 = [PNLineChartData new]; | ||
| 39 | - data01.color = PNFreshGreen; | ||
| 40 | - data01.itemCount = lineChart.xLabels.count; | ||
| 41 | - data01.inflexionPointStyle = PNLineChartPointStyleTriangle; | ||
| 42 | - data01.getData = ^(NSUInteger index) { | ||
| 43 | - CGFloat yValue = [data01Array[index] floatValue]; | ||
| 44 | - return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 45 | - }; | ||
| 46 | - | ||
| 47 | - // Line Chart #2 | ||
| 48 | - NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2]; | ||
| 49 | - PNLineChartData *data02 = [PNLineChartData new]; | ||
| 50 | - data02.color = PNTwitterColor; | ||
| 51 | - data02.itemCount = lineChart.xLabels.count; | ||
| 52 | - data02.inflexionPointStyle = PNLineChartPointStyleSquare; | ||
| 53 | - data02.getData = ^(NSUInteger index) { | ||
| 54 | - CGFloat yValue = [data02Array[index] floatValue]; | ||
| 55 | - return [PNLineChartDataItem dataItemWithY:yValue]; | ||
| 56 | - }; | ||
| 57 | - | ||
| 58 | - lineChart.chartData = @[data01, data02]; | ||
| 59 | - [lineChart strokeChart]; | ||
| 60 | - | ||
| 61 | - lineChart.delegate = self; | ||
| 62 | - | ||
| 63 | - [viewController.view addSubview:lineChartLabel]; | ||
| 64 | - [viewController.view addSubview:lineChart]; | ||
| 65 | 24 | ||
| 66 | viewController.title = @"Line Chart"; | 25 | viewController.title = @"Line Chart"; |
| 67 | 26 |
-
Please register or login to post a comment