Merge pull request #53 from ZhangHang/master
Simple Pie chart for PNChart
Showing
8 changed files
with
385 additions
and
4 deletions
PNChart/PNPieChart/PNPieChart.h
0 → 100644
| 1 | +// | ||
| 2 | +// PNPieChart.h | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Hang Zhang on 14-5-5. | ||
| 6 | +// Copyright (c) 2014年 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <UIKit/UIKit.h> | ||
| 10 | +#import "PNPieChartDataItem.h" | ||
| 11 | + | ||
| 12 | +@interface PNPieChart : UIView | ||
| 13 | + | ||
| 14 | +- (id)initWithFrame:(CGRect)frame items:(NSArray *)items; | ||
| 15 | + | ||
| 16 | +@property (nonatomic, readonly) NSArray *items; | ||
| 17 | + | ||
| 18 | +@property (nonatomic) UIFont *descriptionTextFont; //default is [UIFont fontWithName:@"Avenir-Medium" size:18.0]; | ||
| 19 | +@property (nonatomic) UIColor *descriptionTextColor; //default is [UIColor whiteColor] | ||
| 20 | +@property (nonatomic) UIColor *descriptionTextShadowColor; //default is [[UIColor blackColor] colorWithAlphaComponent:0.4] | ||
| 21 | +@property (nonatomic) CGSize descriptionTextShadowOffset; //default is CGSizeMake(0, 1) | ||
| 22 | +@property (nonatomic) NSTimeInterval duration;//default is 1.0 | ||
| 23 | + | ||
| 24 | +- (void)strokeChart; | ||
| 25 | + | ||
| 26 | +@end |
PNChart/PNPieChart/PNPieChart.m
0 → 100644
| 1 | +// | ||
| 2 | +// PNPieChart.m | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Hang Zhang on 14-5-5. | ||
| 6 | +// Copyright (c) 2014年 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "PNPieChart.h" | ||
| 10 | + | ||
| 11 | +@interface PNPieChart() | ||
| 12 | + | ||
| 13 | +@property (nonatomic, readwrite) NSArray *items; | ||
| 14 | +@property (nonatomic) CGFloat total; | ||
| 15 | +@property (nonatomic) CGFloat currentTotal; | ||
| 16 | + | ||
| 17 | +@property (nonatomic) CGFloat outterCircleRadius; | ||
| 18 | +@property (nonatomic) CGFloat innerCircleRadius; | ||
| 19 | + | ||
| 20 | +@property (nonatomic) UIView *contentView; | ||
| 21 | +@property (nonatomic) CAShapeLayer *pieLayer; | ||
| 22 | +@property (nonatomic) NSMutableArray *descriptionLabels; | ||
| 23 | + | ||
| 24 | +- (void)loadDefault; | ||
| 25 | + | ||
| 26 | +- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; | ||
| 27 | +- (PNPieChartDataItem *)dataItemForIndex:(NSUInteger)index; | ||
| 28 | + | ||
| 29 | +- (CAShapeLayer *)newCircleLayerWithRadius:(CGFloat)radius | ||
| 30 | + borderWidth:(CGFloat)borderWidth | ||
| 31 | + fillColor:(UIColor *)fillColor | ||
| 32 | + borderColor:(UIColor *)borderColor | ||
| 33 | + startPercentage:(CGFloat)startPercentage | ||
| 34 | + endPercentage:(CGFloat)endPercentage; | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +@end | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +@implementation PNPieChart | ||
| 41 | + | ||
| 42 | +-(id)initWithFrame:(CGRect)frame items:(NSArray *)items{ | ||
| 43 | + self = [self initWithFrame:frame]; | ||
| 44 | + if(self){ | ||
| 45 | + _items = [NSArray arrayWithArray:items]; | ||
| 46 | + _outterCircleRadius = CGRectGetWidth(self.bounds)/2; | ||
| 47 | + _innerCircleRadius = CGRectGetWidth(self.bounds)/6; | ||
| 48 | + | ||
| 49 | + _descriptionTextColor = [UIColor whiteColor]; | ||
| 50 | + _descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0]; | ||
| 51 | + _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; | ||
| 52 | + _descriptionTextShadowOffset = CGSizeMake(0, 1); | ||
| 53 | + _duration = 1.0; | ||
| 54 | + | ||
| 55 | + [self loadDefault]; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + return self; | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | + | ||
| 62 | +- (void)loadDefault{ | ||
| 63 | + _currentTotal = 0; | ||
| 64 | + _total = 0; | ||
| 65 | + | ||
| 66 | + [_contentView removeFromSuperview]; | ||
| 67 | + _contentView = [[UIView alloc] initWithFrame:self.bounds]; | ||
| 68 | + [self addSubview:_contentView]; | ||
| 69 | + [_descriptionLabels removeAllObjects]; | ||
| 70 | + _descriptionLabels = [NSMutableArray new]; | ||
| 71 | + | ||
| 72 | + _pieLayer = [CAShapeLayer layer]; | ||
| 73 | + [_contentView.layer addSublayer:_pieLayer]; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +#pragma mark - | ||
| 77 | + | ||
| 78 | +- (void)strokeChart{ | ||
| 79 | + [self loadDefault]; | ||
| 80 | + | ||
| 81 | + [self.items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | ||
| 82 | + _total +=((PNPieChartDataItem *)obj).value; | ||
| 83 | + }]; | ||
| 84 | + | ||
| 85 | + PNPieChartDataItem *currentItem; | ||
| 86 | + CGFloat currentValue = 0; | ||
| 87 | + for (int i = 0; i < _items.count; i++) { | ||
| 88 | + currentItem = [self dataItemForIndex:i]; | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + CGFloat startPercnetage = currentValue/_total; | ||
| 92 | + CGFloat endPercentage = (currentValue + currentItem.value)/_total; | ||
| 93 | + | ||
| 94 | + CAShapeLayer *currentPieLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outterCircleRadius - _innerCircleRadius)/2 | ||
| 95 | + borderWidth:_outterCircleRadius - _innerCircleRadius | ||
| 96 | + fillColor:[UIColor clearColor] | ||
| 97 | + borderColor:currentItem.color | ||
| 98 | + startPercentage:startPercnetage | ||
| 99 | + endPercentage:endPercentage]; | ||
| 100 | + [_pieLayer addSublayer:currentPieLayer]; | ||
| 101 | + | ||
| 102 | + currentValue+=currentItem.value; | ||
| 103 | + | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + [self maskChart]; | ||
| 107 | + | ||
| 108 | + currentValue = 0; | ||
| 109 | + for (int i = 0; i < _items.count; i++) { | ||
| 110 | + currentItem = [self dataItemForIndex:i]; | ||
| 111 | + UILabel *descriptionLabel = [self descriptionLabelForItemAtIndex:i]; | ||
| 112 | + [_contentView addSubview:descriptionLabel]; | ||
| 113 | + currentValue+=currentItem.value; | ||
| 114 | + [_descriptionLabels addObject:descriptionLabel]; | ||
| 115 | + } | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{ | ||
| 119 | + PNPieChartDataItem *currentDataItem = [self dataItemForIndex:index]; | ||
| 120 | + CGFloat distance = _innerCircleRadius + (_outterCircleRadius - _innerCircleRadius) / 2; | ||
| 121 | + CGFloat centerPercentage =(_currentTotal + currentDataItem.value /2 ) / _total; | ||
| 122 | + CGFloat rad = centerPercentage * 2 * M_PI; | ||
| 123 | + | ||
| 124 | + _currentTotal += currentDataItem.value; | ||
| 125 | + | ||
| 126 | + NSString *titleText = currentDataItem.description; | ||
| 127 | + if(!titleText){ | ||
| 128 | + titleText = [NSString stringWithFormat:@"%.0f%%",currentDataItem.value/ _total * 100]; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + CGPoint center = CGPointMake(_outterCircleRadius + distance * sin(rad), | ||
| 132 | + _outterCircleRadius - distance * cos(rad)); | ||
| 133 | + | ||
| 134 | + CGRect frame; | ||
| 135 | + frame.size = CGSizeMake(100, 80); | ||
| 136 | + | ||
| 137 | + UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame]; | ||
| 138 | + [descriptionLabel setText:titleText]; | ||
| 139 | + [descriptionLabel setFont:_descriptionTextFont]; | ||
| 140 | + [descriptionLabel setTextColor:_descriptionTextColor]; | ||
| 141 | + [descriptionLabel setShadowColor:_descriptionTextShadowColor]; | ||
| 142 | + [descriptionLabel setShadowOffset:_descriptionTextShadowOffset]; | ||
| 143 | + [descriptionLabel setTextAlignment:NSTextAlignmentCenter]; | ||
| 144 | + [descriptionLabel setCenter:center]; | ||
| 145 | + [descriptionLabel setAlpha:0]; | ||
| 146 | + | ||
| 147 | + | ||
| 148 | + return descriptionLabel; | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +- (PNPieChartDataItem *)dataItemForIndex:(NSUInteger)index{ | ||
| 152 | + return self.items[index]; | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +#pragma mark private methods | ||
| 156 | + | ||
| 157 | +- (CAShapeLayer *)newCircleLayerWithRadius:(CGFloat)radius | ||
| 158 | + borderWidth:(CGFloat)borderWidth | ||
| 159 | + fillColor:(UIColor *)fillColor | ||
| 160 | + borderColor:(UIColor *)borderColor | ||
| 161 | + startPercentage:(CGFloat)startPercentage | ||
| 162 | + endPercentage:(CGFloat)endPercentage{ | ||
| 163 | + CAShapeLayer *circle = [CAShapeLayer layer]; | ||
| 164 | + | ||
| 165 | + CGPoint center = CGPointMake(CGRectGetMidX(self.bounds),CGRectGetMidY(self.bounds)); | ||
| 166 | + | ||
| 167 | + UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center | ||
| 168 | + radius:radius | ||
| 169 | + startAngle:-M_PI_2 | ||
| 170 | + endAngle:M_PI_2 * 3 | ||
| 171 | + clockwise:YES]; | ||
| 172 | + | ||
| 173 | + circle.fillColor = fillColor.CGColor; | ||
| 174 | + circle.strokeColor = borderColor.CGColor; | ||
| 175 | + circle.strokeStart = startPercentage; | ||
| 176 | + circle.strokeEnd = endPercentage; | ||
| 177 | + circle.lineWidth = borderWidth; | ||
| 178 | + circle.path = path.CGPath; | ||
| 179 | + | ||
| 180 | + | ||
| 181 | + return circle; | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +- (void)maskChart{ | ||
| 185 | + CAShapeLayer *maskLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outterCircleRadius - _innerCircleRadius)/2 | ||
| 186 | + borderWidth:_outterCircleRadius - _innerCircleRadius | ||
| 187 | + fillColor:[UIColor clearColor] | ||
| 188 | + borderColor:[UIColor blackColor] | ||
| 189 | + startPercentage:0 | ||
| 190 | + endPercentage:1]; | ||
| 191 | + | ||
| 192 | + _pieLayer.mask = maskLayer; | ||
| 193 | + CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | ||
| 194 | + animation.duration = _duration; | ||
| 195 | + animation.fromValue = @0; | ||
| 196 | + animation.toValue = @1; | ||
| 197 | + animation.delegate = self; | ||
| 198 | + animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | ||
| 199 | + animation.removedOnCompletion = YES; | ||
| 200 | + [maskLayer addAnimation:animation forKey:@"circleAnimation"]; | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +- (void)createArcAnimationForLayer:(CAShapeLayer *)layer ForKey:(NSString *)key fromValue:(NSNumber *)from toValue:(NSNumber *)to Delegate:(id)delegate | ||
| 204 | +{ | ||
| 205 | + CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:key]; | ||
| 206 | + arcAnimation.fromValue = @0; | ||
| 207 | + [arcAnimation setToValue:to]; | ||
| 208 | + [arcAnimation setDelegate:delegate]; | ||
| 209 | + [arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; | ||
| 210 | + [layer addAnimation:arcAnimation forKey:key]; | ||
| 211 | + [layer setValue:to forKey:key]; | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ | ||
| 215 | + [_descriptionLabels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | ||
| 216 | + [UIView animateWithDuration:0.2 animations:^(){ | ||
| 217 | + [obj setAlpha:1]; | ||
| 218 | + }]; | ||
| 219 | + }]; | ||
| 220 | +} | ||
| 221 | +@end |
PNChart/PNPieChart/PNPieChartDataItem.h
0 → 100644
| 1 | +// | ||
| 2 | +// PNPieChartDataItem.h | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Hang Zhang on 14-5-5. | ||
| 6 | +// Copyright (c) 2014年 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | + | ||
| 11 | +@interface PNPieChartDataItem : NSObject | ||
| 12 | + | ||
| 13 | ++ (instancetype)dataItemWithValue:(CGFloat)value | ||
| 14 | + color:(UIColor*)color; | ||
| 15 | + | ||
| 16 | ++ (instancetype)dataItemWithValue:(CGFloat)value | ||
| 17 | + color:(UIColor*)color | ||
| 18 | + description:(NSString *)description; | ||
| 19 | + | ||
| 20 | +@property (nonatomic, readonly) CGFloat value; | ||
| 21 | +@property (nonatomic, readonly) UIColor *color; | ||
| 22 | +@property (nonatomic, readonly) NSString *description; | ||
| 23 | + | ||
| 24 | +@end |
PNChart/PNPieChart/PNPieChartDataItem.m
0 → 100644
| 1 | +// | ||
| 2 | +// PNPieChartDataItem.m | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Hang Zhang on 14-5-5. | ||
| 6 | +// Copyright (c) 2014年 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "PNPieChartDataItem.h" | ||
| 10 | + | ||
| 11 | +@interface PNPieChartDataItem() | ||
| 12 | + | ||
| 13 | +@property (nonatomic, readwrite) CGFloat value; | ||
| 14 | +@property (nonatomic, readwrite) UIColor *color; | ||
| 15 | +@property (nonatomic, readwrite) NSString *description; | ||
| 16 | + | ||
| 17 | +@end | ||
| 18 | + | ||
| 19 | +@implementation PNPieChartDataItem | ||
| 20 | + | ||
| 21 | + | ||
| 22 | ++ (instancetype)dataItemWithValue:(CGFloat)value | ||
| 23 | + color:(UIColor*)color{ | ||
| 24 | + PNPieChartDataItem *item = [PNPieChartDataItem new]; | ||
| 25 | + item.value = value; | ||
| 26 | + item.color = color; | ||
| 27 | + return item; | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | ++ (instancetype)dataItemWithValue:(CGFloat)value | ||
| 31 | + color:(UIColor*)color | ||
| 32 | + description:(NSString *)description{ | ||
| 33 | + PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:value color:color]; | ||
| 34 | + item.description = description; | ||
| 35 | + return item; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +@end |
| @@ -32,6 +32,8 @@ | @@ -32,6 +32,8 @@ | ||
| 32 | 9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF3190BB014004129F5 /* PNLineChartData.m */; }; | 32 | 9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF3190BB014004129F5 /* PNLineChartData.m */; }; |
| 33 | 9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */; }; | 33 | 9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */; }; |
| 34 | E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; }; | 34 | E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; }; |
| 35 | + F938F7E11917727E00B4448E /* PNPieChart.m in Sources */ = {isa = PBXBuildFile; fileRef = F938F7E01917727E00B4448E /* PNPieChart.m */; }; | ||
| 36 | + F938F7E4191772F200B4448E /* PNPieChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F938F7E3191772F200B4448E /* PNPieChartDataItem.m */; }; | ||
| 35 | /* End PBXBuildFile section */ | 37 | /* End PBXBuildFile section */ |
| 36 | 38 | ||
| 37 | /* Begin PBXContainerItemProxy section */ | 39 | /* Begin PBXContainerItemProxy section */ |
| @@ -87,6 +89,10 @@ | @@ -87,6 +89,10 @@ | ||
| 87 | 9FE15DF4190BB014004129F5 /* PNLineChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartDataItem.h; sourceTree = "<group>"; }; | 89 | 9FE15DF4190BB014004129F5 /* PNLineChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartDataItem.h; sourceTree = "<group>"; }; |
| 88 | 9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartDataItem.m; sourceTree = "<group>"; }; | 90 | 9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartDataItem.m; sourceTree = "<group>"; }; |
| 89 | F161CF4F7A8C4BD2AB65FB4F /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; }; | 91 | F161CF4F7A8C4BD2AB65FB4F /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; }; |
| 92 | + F938F7DF1917727E00B4448E /* PNPieChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNPieChart.h; sourceTree = "<group>"; }; | ||
| 93 | + F938F7E01917727E00B4448E /* PNPieChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNPieChart.m; sourceTree = "<group>"; }; | ||
| 94 | + F938F7E2191772F200B4448E /* PNPieChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNPieChartDataItem.h; sourceTree = "<group>"; }; | ||
| 95 | + F938F7E3191772F200B4448E /* PNPieChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNPieChartDataItem.m; sourceTree = "<group>"; }; | ||
| 90 | /* End PBXFileReference section */ | 96 | /* End PBXFileReference section */ |
| 91 | 97 | ||
| 92 | /* Begin PBXFrameworksBuildPhase section */ | 98 | /* Begin PBXFrameworksBuildPhase section */ |
| @@ -205,6 +211,7 @@ | @@ -205,6 +211,7 @@ | ||
| 205 | 9FE15DE0190BB014004129F5 /* PNChart */ = { | 211 | 9FE15DE0190BB014004129F5 /* PNChart */ = { |
| 206 | isa = PBXGroup; | 212 | isa = PBXGroup; |
| 207 | children = ( | 213 | children = ( |
| 214 | + F938F7DE191770FE00B4448E /* PNPieChart */, | ||
| 208 | 9FE15DE1190BB014004129F5 /* PNBarChart */, | 215 | 9FE15DE1190BB014004129F5 /* PNBarChart */, |
| 209 | 9FE15DE6190BB014004129F5 /* PNChart.h */, | 216 | 9FE15DE6190BB014004129F5 /* PNChart.h */, |
| 210 | 9FE15DE7190BB014004129F5 /* PNChartDelegate.h */, | 217 | 9FE15DE7190BB014004129F5 /* PNChartDelegate.h */, |
| @@ -251,6 +258,17 @@ | @@ -251,6 +258,17 @@ | ||
| 251 | path = PNLineChart; | 258 | path = PNLineChart; |
| 252 | sourceTree = "<group>"; | 259 | sourceTree = "<group>"; |
| 253 | }; | 260 | }; |
| 261 | + F938F7DE191770FE00B4448E /* PNPieChart */ = { | ||
| 262 | + isa = PBXGroup; | ||
| 263 | + children = ( | ||
| 264 | + F938F7DF1917727E00B4448E /* PNPieChart.h */, | ||
| 265 | + F938F7E01917727E00B4448E /* PNPieChart.m */, | ||
| 266 | + F938F7E2191772F200B4448E /* PNPieChartDataItem.h */, | ||
| 267 | + F938F7E3191772F200B4448E /* PNPieChartDataItem.m */, | ||
| 268 | + ); | ||
| 269 | + path = PNPieChart; | ||
| 270 | + sourceTree = "<group>"; | ||
| 271 | + }; | ||
| 254 | /* End PBXGroup section */ | 272 | /* End PBXGroup section */ |
| 255 | 273 | ||
| 256 | /* Begin PBXNativeTarget section */ | 274 | /* Begin PBXNativeTarget section */ |
| @@ -392,9 +410,11 @@ | @@ -392,9 +410,11 @@ | ||
| 392 | 9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */, | 410 | 9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */, |
| 393 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */, | 411 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */, |
| 394 | 9FE15DF9190BB014004129F5 /* PNCircleChart.m in Sources */, | 412 | 9FE15DF9190BB014004129F5 /* PNCircleChart.m in Sources */, |
| 413 | + F938F7E4191772F200B4448E /* PNPieChartDataItem.m in Sources */, | ||
| 395 | 0AF7A874182AA9F6003645C4 /* main.m in Sources */, | 414 | 0AF7A874182AA9F6003645C4 /* main.m in Sources */, |
| 396 | 9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */, | 415 | 9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */, |
| 397 | 9FE15DF7190BB014004129F5 /* PNBarChart.m in Sources */, | 416 | 9FE15DF7190BB014004129F5 /* PNBarChart.m in Sources */, |
| 417 | + F938F7E11917727E00B4448E /* PNPieChart.m in Sources */, | ||
| 398 | 0AF7A878182AA9F6003645C4 /* PCAppDelegate.m in Sources */, | 418 | 0AF7A878182AA9F6003645C4 /* PCAppDelegate.m in Sources */, |
| 399 | ); | 419 | ); |
| 400 | runOnlyForDeploymentPostprocessing = 0; | 420 | runOnlyForDeploymentPostprocessing = 0; |
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13A2093" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH"> | 2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH"> |
| 3 | <dependencies> | 3 | <dependencies> |
| 4 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/> | 4 | + <deployment defaultVersion="1536" identifier="iOS"/> |
| 5 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/> | ||
| 5 | </dependencies> | 6 | </dependencies> |
| 6 | <scenes> | 7 | <scenes> |
| 7 | <!--Chart View Controller - PNChart--> | 8 | <!--Chart View Controller - PNChart--> |
| @@ -94,6 +95,26 @@ | @@ -94,6 +95,26 @@ | ||
| 94 | <segue destination="Tha-Wr-sPW" kind="push" identifier="circleChart" id="WSA-oe-ed1"/> | 95 | <segue destination="Tha-Wr-sPW" kind="push" identifier="circleChart" id="WSA-oe-ed1"/> |
| 95 | </connections> | 96 | </connections> |
| 96 | </tableViewCell> | 97 | </tableViewCell> |
| 98 | + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="N5A-vO-fq4" style="IBUITableViewCellStyleDefault" id="1Ha-E5-to7"> | ||
| 99 | + <rect key="frame" x="0.0" y="196" width="320" height="44"/> | ||
| 100 | + <autoresizingMask key="autoresizingMask"/> | ||
| 101 | + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1Ha-E5-to7" id="3YW-gb-VCd"> | ||
| 102 | + <rect key="frame" x="0.0" y="0.0" width="287" height="43"/> | ||
| 103 | + <autoresizingMask key="autoresizingMask"/> | ||
| 104 | + <subviews> | ||
| 105 | + <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="PieChart" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="N5A-vO-fq4"> | ||
| 106 | + <rect key="frame" x="15" y="0.0" width="270" height="43"/> | ||
| 107 | + <autoresizingMask key="autoresizingMask"/> | ||
| 108 | + <fontDescription key="fontDescription" type="system" pointSize="18"/> | ||
| 109 | + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
| 110 | + <nil key="highlightedColor"/> | ||
| 111 | + </label> | ||
| 112 | + </subviews> | ||
| 113 | + </tableViewCellContentView> | ||
| 114 | + <connections> | ||
| 115 | + <segue destination="Tha-Wr-sPW" kind="push" identifier="pieChart" id="pvQ-oy-a9a"/> | ||
| 116 | + </connections> | ||
| 117 | + </tableViewCell> | ||
| 97 | </cells> | 118 | </cells> |
| 98 | </tableViewSection> | 119 | </tableViewSection> |
| 99 | </sections> | 120 | </sections> |
| @@ -126,6 +147,6 @@ | @@ -126,6 +147,6 @@ | ||
| 126 | <simulatedScreenMetrics key="destination" type="retina4"/> | 147 | <simulatedScreenMetrics key="destination" type="retina4"/> |
| 127 | </simulatedMetricsContainer> | 148 | </simulatedMetricsContainer> |
| 128 | <inferredMetricsTieBreakers> | 149 | <inferredMetricsTieBreakers> |
| 129 | - <segue reference="XHj-XM-h67"/> | 150 | + <segue reference="pvQ-oy-a9a"/> |
| 130 | </inferredMetricsTieBreakers> | 151 | </inferredMetricsTieBreakers> |
| 131 | -</document> | 152 | +</document> |
| @@ -145,6 +145,36 @@ | @@ -145,6 +145,36 @@ | ||
| 145 | [viewController.view addSubview:circleChart]; | 145 | [viewController.view addSubview:circleChart]; |
| 146 | viewController.title = @"Circle Chart"; | 146 | viewController.title = @"Circle Chart"; |
| 147 | 147 | ||
| 148 | + }else if ([segue.identifier isEqualToString:@"pieChart"]) | ||
| 149 | + { | ||
| 150 | + | ||
| 151 | + //Add LineChart | ||
| 152 | + UILabel * pieChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)]; | ||
| 153 | + pieChartLabel.text = @"Pie Chart"; | ||
| 154 | + pieChartLabel.textColor = PNFreshGreen; | ||
| 155 | + pieChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0]; | ||
| 156 | + pieChartLabel.textAlignment = NSTextAlignmentCenter; | ||
| 157 | + | ||
| 158 | + | ||
| 159 | + | ||
| 160 | + NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNRed], | ||
| 161 | + [PNPieChartDataItem dataItemWithValue:20 color:PNBlue description:@"WWDC"], | ||
| 162 | + [PNPieChartDataItem dataItemWithValue:40 color:PNGreen description:@"Google I/O"], | ||
| 163 | + ]; | ||
| 164 | + | ||
| 165 | + | ||
| 166 | + | ||
| 167 | + PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, SCREEN_WIDTH) items:items]; | ||
| 168 | + pieChart.descriptionTextColor = [UIColor whiteColor]; | ||
| 169 | + pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0]; | ||
| 170 | + [pieChart strokeChart]; | ||
| 171 | + | ||
| 172 | + | ||
| 173 | + [viewController.view addSubview:pieChartLabel]; | ||
| 174 | + [viewController.view addSubview:pieChart]; | ||
| 175 | + | ||
| 176 | + viewController.title = @"Pie Chart"; | ||
| 177 | + | ||
| 148 | } | 178 | } |
| 149 | 179 | ||
| 150 | } | 180 | } |
-
Please register or login to post a comment