Showing
11 changed files
with
203 additions
and
10 deletions
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | +#import "PNGenericChart.h" | ||
| 10 | #import "PNChartDelegate.h" | 11 | #import "PNChartDelegate.h" |
| 11 | #import "PNBar.h" | 12 | #import "PNBar.h" |
| 12 | 13 | ||
| @@ -17,7 +18,7 @@ | @@ -17,7 +18,7 @@ | ||
| 17 | 18 | ||
| 18 | typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | 19 | typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); |
| 19 | 20 | ||
| 20 | -@interface PNBarChart : UIView | 21 | +@interface PNBarChart : PNGenericChart |
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | * Draws the chart in an animated fashion. | 24 | * Draws the chart in an animated fashion. |
PNChart/PNGenericChart.h
0 → 100644
| 1 | +// | ||
| 2 | +// PNGenericChart.h | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Andi Palo on 26/02/15. | ||
| 6 | +// Copyright (c) 2015 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <UIKit/UIKit.h> | ||
| 10 | + | ||
| 11 | +typedef NS_ENUM(NSUInteger, PNLegendPosition) { | ||
| 12 | + PNLegendPositionTop = 0, | ||
| 13 | + PNLegendPositionBottom = 1, | ||
| 14 | + PNLegendPositionLeft = 2, | ||
| 15 | + PNLegendPositionRight = 3 | ||
| 16 | +}; | ||
| 17 | + | ||
| 18 | +typedef NS_ENUM(NSUInteger, PNLegendItemStyle) { | ||
| 19 | + PNLegendItemStyleStacked = 0, | ||
| 20 | + PNLegendItemStyleSerial = 1 | ||
| 21 | +}; | ||
| 22 | + | ||
| 23 | +@interface PNGenericChart : UIView | ||
| 24 | + | ||
| 25 | +@property (assign, nonatomic) BOOL hasLegend; | ||
| 26 | +@property (assign, nonatomic) PNLegendPosition legendPosition; | ||
| 27 | +@property (assign, nonatomic) PNLegendItemStyle legendStyle; | ||
| 28 | +@property (assign, nonatomic) CGFloat legendFontSize; | ||
| 29 | + | ||
| 30 | +- (UIView*) drawLegend; | ||
| 31 | + | ||
| 32 | +@end |
PNChart/PNGenericChart.m
0 → 100644
| 1 | +// | ||
| 2 | +// PNGenericChart.m | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Andi Palo on 26/02/15. | ||
| 6 | +// Copyright (c) 2015 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "PNGenericChart.h" | ||
| 10 | + | ||
| 11 | +@interface PNGenericChart () | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +@end | ||
| 16 | + | ||
| 17 | +@implementation PNGenericChart | ||
| 18 | + | ||
| 19 | +/* | ||
| 20 | +// Only override drawRect: if you perform custom drawing. | ||
| 21 | +// An empty implementation adversely affects performance during animation. | ||
| 22 | +- (void)drawRect:(CGRect)rect { | ||
| 23 | + // Drawing code | ||
| 24 | +} | ||
| 25 | +*/ | ||
| 26 | + | ||
| 27 | +- (UIView*) drawLegend{ | ||
| 28 | + return nil; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +- (id)initWithCoder:(NSCoder *)coder | ||
| 33 | +{ | ||
| 34 | + self = [super initWithCoder:coder]; | ||
| 35 | + | ||
| 36 | + if (self) { | ||
| 37 | + [self setupDefaultValues]; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + return self; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +- (id)initWithFrame:(CGRect)frame | ||
| 44 | +{ | ||
| 45 | + self = [super initWithFrame:frame]; | ||
| 46 | + | ||
| 47 | + if (self) { | ||
| 48 | + [self setupDefaultValues]; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + return self; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +- (void) setupDefaultValues{ | ||
| 55 | + self.hasLegend = YES; | ||
| 56 | + self.legendPosition = PNLegendPositionBottom; | ||
| 57 | + self.legendStyle = PNLegendItemStyleStacked; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +@end |
| @@ -9,8 +9,9 @@ | @@ -9,8 +9,9 @@ | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | #import <QuartzCore/QuartzCore.h> | 10 | #import <QuartzCore/QuartzCore.h> |
| 11 | #import "PNChartDelegate.h" | 11 | #import "PNChartDelegate.h" |
| 12 | +#import "PNGenericChart.h" | ||
| 12 | 13 | ||
| 13 | -@interface PNLineChart : UIView | 14 | +@interface PNLineChart : PNGenericChart |
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * Draws the chart in an animated fashion. | 17 | * Draws the chart in an animated fashion. |
| @@ -70,4 +71,5 @@ | @@ -70,4 +71,5 @@ | ||
| 70 | 71 | ||
| 71 | - (void)updateChartData:(NSArray *)data; | 72 | - (void)updateChartData:(NSArray *)data; |
| 72 | 73 | ||
| 74 | +- (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth; | ||
| 73 | @end | 75 | @end |
| @@ -20,6 +20,10 @@ | @@ -20,6 +20,10 @@ | ||
| 20 | @property (nonatomic) NSMutableArray *chartPath; // Array of line path, one for each line. | 20 | @property (nonatomic) NSMutableArray *chartPath; // Array of line path, one for each line. |
| 21 | @property (nonatomic) NSMutableArray *pointPath; // Array of point path, one for each line | 21 | @property (nonatomic) NSMutableArray *pointPath; // Array of point path, one for each line |
| 22 | @property (nonatomic) NSMutableArray *endPointsOfPath; // Array of start and end points of each line path, one for each line | 22 | @property (nonatomic) NSMutableArray *endPointsOfPath; // Array of start and end points of each line path, one for each line |
| 23 | + | ||
| 24 | +@property (strong, nonatomic) UIView *graphView; | ||
| 25 | + | ||
| 26 | +@property (assign, nonatomic) CGRect *chartFrame; | ||
| 23 | @end | 27 | @end |
| 24 | 28 | ||
| 25 | @implementation PNLineChart | 29 | @implementation PNLineChart |
| @@ -48,6 +52,7 @@ | @@ -48,6 +52,7 @@ | ||
| 48 | return self; | 52 | return self; |
| 49 | } | 53 | } |
| 50 | 54 | ||
| 55 | + | ||
| 51 | #pragma mark instance methods | 56 | #pragma mark instance methods |
| 52 | 57 | ||
| 53 | - (void)setYLabels:(NSArray *)yLabels | 58 | - (void)setYLabels:(NSArray *)yLabels |
| @@ -64,6 +69,7 @@ | @@ -64,6 +69,7 @@ | ||
| 64 | _yChartLabels = [NSMutableArray new]; | 69 | _yChartLabels = [NSMutableArray new]; |
| 65 | } | 70 | } |
| 66 | 71 | ||
| 72 | +#warning modify origin | ||
| 67 | if (yStep == 0.0) { | 73 | if (yStep == 0.0) { |
| 68 | PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger)_chartCavanHeight, (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; | 74 | PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger)_chartCavanHeight, (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; |
| 69 | minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; | 75 | minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; |
| @@ -132,6 +138,7 @@ | @@ -132,6 +138,7 @@ | ||
| 132 | for (int index = 0; index < xLabels.count; index++) { | 138 | for (int index = 0; index < xLabels.count; index++) { |
| 133 | labelText = xLabels[index]; | 139 | labelText = xLabels[index]; |
| 134 | 140 | ||
| 141 | +#warning modify origin | ||
| 135 | NSInteger x = 2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2); | 142 | NSInteger x = 2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2); |
| 136 | NSInteger y = _chartMargin + _chartCavanHeight; | 143 | NSInteger y = _chartMargin + _chartCavanHeight; |
| 137 | 144 | ||
| @@ -337,6 +344,7 @@ | @@ -337,6 +344,7 @@ | ||
| 337 | 344 | ||
| 338 | CGFloat offSetX = (_chartCavanWidth) / (chartData.itemCount); | 345 | CGFloat offSetX = (_chartCavanWidth) / (chartData.itemCount); |
| 339 | 346 | ||
| 347 | +#warning modify chart path | ||
| 340 | int x = 2 * _chartMargin + (i * offSetX); | 348 | int x = 2 * _chartMargin + (i * offSetX); |
| 341 | int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2); | 349 | int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2); |
| 342 | 350 | ||
| @@ -585,7 +593,7 @@ | @@ -585,7 +593,7 @@ | ||
| 585 | - (void)drawRect:(CGRect)rect | 593 | - (void)drawRect:(CGRect)rect |
| 586 | { | 594 | { |
| 587 | if (self.isShowCoordinateAxis) { | 595 | if (self.isShowCoordinateAxis) { |
| 588 | - | 596 | +#warning modify |
| 589 | CGFloat yAxisOffset = 10.f; | 597 | CGFloat yAxisOffset = 10.f; |
| 590 | 598 | ||
| 591 | CGContextRef ctx = UIGraphicsGetCurrentContext(); | 599 | CGContextRef ctx = UIGraphicsGetCurrentContext(); |
| @@ -639,14 +647,14 @@ | @@ -639,14 +647,14 @@ | ||
| 639 | 647 | ||
| 640 | // draw y unit | 648 | // draw y unit |
| 641 | if ([self.yUnit length]) { | 649 | if ([self.yUnit length]) { |
| 642 | - CGFloat height = [PNLineChart heightOfString:self.yUnit withWidth:30.f font:font]; | 650 | + CGFloat height = [PNLineChart sizeOfString:self.yUnit withWidth:30.f font:font].height; |
| 643 | CGRect drawRect = CGRectMake(_chartMargin + 10 + 5, 0, 30.f, height); | 651 | CGRect drawRect = CGRectMake(_chartMargin + 10 + 5, 0, 30.f, height); |
| 644 | [self drawTextInContext:ctx text:self.yUnit inRect:drawRect font:font]; | 652 | [self drawTextInContext:ctx text:self.yUnit inRect:drawRect font:font]; |
| 645 | } | 653 | } |
| 646 | 654 | ||
| 647 | // draw x unit | 655 | // draw x unit |
| 648 | if ([self.xUnit length]) { | 656 | if ([self.xUnit length]) { |
| 649 | - CGFloat height = [PNLineChart heightOfString:self.xUnit withWidth:30.f font:font]; | 657 | + CGFloat height = [PNLineChart sizeOfString:self.xUnit withWidth:30.f font:font].height; |
| 650 | CGRect drawRect = CGRectMake(CGRectGetWidth(rect) - _chartMargin + 5, _chartMargin + _chartCavanHeight - height / 2, 25.f, height); | 658 | CGRect drawRect = CGRectMake(CGRectGetWidth(rect) - _chartMargin + 5, _chartMargin + _chartCavanHeight - height / 2, 25.f, height); |
| 651 | [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font]; | 659 | [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font]; |
| 652 | } | 660 | } |
| @@ -684,7 +692,7 @@ | @@ -684,7 +692,7 @@ | ||
| 684 | 692 | ||
| 685 | #pragma mark - tools | 693 | #pragma mark - tools |
| 686 | 694 | ||
| 687 | -+ (float)heightOfString:(NSString *)text withWidth:(float)width font:(UIFont *)font | 695 | ++ (CGSize)sizeOfString:(NSString *)text withWidth:(float)width font:(UIFont *)font |
| 688 | { | 696 | { |
| 689 | NSInteger ch; | 697 | NSInteger ch; |
| 690 | CGSize size = CGSizeMake(width, MAXFLOAT); | 698 | CGSize size = CGSizeMake(width, MAXFLOAT); |
| @@ -703,7 +711,7 @@ | @@ -703,7 +711,7 @@ | ||
| 703 | } | 711 | } |
| 704 | ch = size.height; | 712 | ch = size.height; |
| 705 | 713 | ||
| 706 | - return ch; | 714 | + return size; |
| 707 | } | 715 | } |
| 708 | 716 | ||
| 709 | - (void)drawTextInContext:(CGContextRef )ctx text:(NSString *)text inRect:(CGRect)rect font:(UIFont *)font | 717 | - (void)drawTextInContext:(CGContextRef )ctx text:(NSString *)text inRect:(CGRect)rect font:(UIFont *)font |
| @@ -726,4 +734,80 @@ | @@ -726,4 +734,80 @@ | ||
| 726 | } | 734 | } |
| 727 | } | 735 | } |
| 728 | 736 | ||
| 737 | +- (UIView*) constructLegend{ | ||
| 738 | + if (self.hasLegend) { | ||
| 739 | + UIView *legend = [self constructLegend]; | ||
| 740 | + CGSize graphSize; | ||
| 741 | + /* Determine legend size */ | ||
| 742 | + switch (self.legendPosition) { | ||
| 743 | + case PNLegendPositionTop | PNLegendPositionBottom: | ||
| 744 | + graphSize = CGSizeMake(fmaxf(self.frame.size.width, legend.frame.size.width), self.frame.size.height + legend.frame.size.height); | ||
| 745 | + break; | ||
| 746 | + case PNLegendPositionLeft | PNLegendPositionRight: | ||
| 747 | + graphSize = CGSizeMake(self.frame.size.width + legend.frame.size.width, fmaxf(self.frame.size.height, legend.frame.size.height)); | ||
| 748 | + break; | ||
| 749 | + default: | ||
| 750 | + break; | ||
| 751 | + } | ||
| 752 | + CGPoint graphOrigin; | ||
| 753 | + switch (self.legendPosition) { | ||
| 754 | + case PNLegendPositionTop: | ||
| 755 | + graphOrigin.x = 2; | ||
| 756 | + break; | ||
| 757 | + case PNLegendPositionBottom: | ||
| 758 | + graphOrigin.x = 2; | ||
| 759 | + break; | ||
| 760 | + case PNLegendPositionLeft: | ||
| 761 | + | ||
| 762 | + case PNLegendPositionRight: | ||
| 763 | + graphOrigin.x = 2; | ||
| 764 | + break; | ||
| 765 | + default: | ||
| 766 | + break; | ||
| 767 | + } | ||
| 768 | + self.graphView = [[UIView alloc] initWithFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, graphSize.width, graphSize.height)]; | ||
| 769 | + [self.graphView addSubview:self]; | ||
| 770 | + [self.graphView addSubview:legend]; | ||
| 771 | + return self.graphView; | ||
| 772 | + }else{ | ||
| 773 | + [self strokeChart]; | ||
| 774 | + return self; | ||
| 775 | + } | ||
| 776 | +} | ||
| 777 | + | ||
| 778 | +- (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{ | ||
| 779 | + if ([self.chartData count] < 1) { | ||
| 780 | + return nil; | ||
| 781 | + } | ||
| 782 | + CGFloat legendLineWidth = 40; | ||
| 783 | + CGFloat x = legendLineWidth; | ||
| 784 | + CGFloat y = 0; | ||
| 785 | + CGFloat totalWidth = 0; | ||
| 786 | + CGFloat totalHeight = 0; | ||
| 787 | + | ||
| 788 | + NSMutableArray *legendLabels = [[NSMutableArray alloc] init]; | ||
| 789 | + for (PNLineChartData *pdata in self.chartData) { | ||
| 790 | + CGFloat maxLabelWidth = self.legendStyle == PNLegendItemStyleStacked ? (mWidth - legendLineWidth) : (mWidth / [self.chartData count] - legendLineWidth); | ||
| 791 | + | ||
| 792 | + CGSize labelsize = [PNLineChart sizeOfString:pdata.dataTitle | ||
| 793 | + withWidth:maxLabelWidth | ||
| 794 | + font:[UIFont systemFontOfSize:self.legendFontSize]]; | ||
| 795 | + | ||
| 796 | + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, maxLabelWidth, labelsize.height)]; | ||
| 797 | + label.text = pdata.dataTitle; | ||
| 798 | + x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + legendLineWidth; | ||
| 799 | + y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0; | ||
| 800 | + | ||
| 801 | + totalWidth = self.legendStyle == PNLegendItemStyleStacked ? fmaxf(totalWidth, labelsize.width + legendLineWidth) : totalWidth + labelsize.width + legendLineWidth; | ||
| 802 | + totalHeight = self.legendStyle == PNLegendItemStyleStacked ? fmaxf(totalHeight, labelsize.height) : totalHeight + labelsize.height; | ||
| 803 | + [legendLabels addObject:label]; | ||
| 804 | + } | ||
| 805 | + | ||
| 806 | + UIView *legend = [[UIView alloc] initWithFrame:CGRectMake(100, 100, totalWidth, totalHeight)]; | ||
| 807 | + for (UILabel *l in legendLabels) { | ||
| 808 | + [legend addSubview:l]; | ||
| 809 | + } | ||
| 810 | + return legend; | ||
| 811 | +} | ||
| 812 | + | ||
| 729 | @end | 813 | @end |
| @@ -22,6 +22,7 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item); | @@ -22,6 +22,7 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item); | ||
| 22 | @property (nonatomic) CGFloat alpha; | 22 | @property (nonatomic) CGFloat alpha; |
| 23 | @property NSUInteger itemCount; | 23 | @property NSUInteger itemCount; |
| 24 | @property (copy) LCLineChartDataGetter getData; | 24 | @property (copy) LCLineChartDataGetter getData; |
| 25 | +@property (strong, nonatomic) NSString *dataTitle; | ||
| 25 | 26 | ||
| 26 | @property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle; | 27 | @property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle; |
| 27 | 28 |
| @@ -8,8 +8,9 @@ | @@ -8,8 +8,9 @@ | ||
| 8 | 8 | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | #import "PNPieChartDataItem.h" | 10 | #import "PNPieChartDataItem.h" |
| 11 | +#import "PNGenericChart.h" | ||
| 11 | 12 | ||
| 12 | -@interface PNPieChart : UIView | 13 | +@interface PNPieChart : PNGenericChart |
| 13 | 14 | ||
| 14 | - (id)initWithFrame:(CGRect)frame items:(NSArray *)items; | 15 | - (id)initWithFrame:(CGRect)frame items:(NSArray *)items; |
| 15 | 16 |
| @@ -9,10 +9,11 @@ | @@ -9,10 +9,11 @@ | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | #import <QuartzCore/QuartzCore.h> | 10 | #import <QuartzCore/QuartzCore.h> |
| 11 | #import "PNChartDelegate.h" | 11 | #import "PNChartDelegate.h" |
| 12 | +#import "PNGenericChart.h" | ||
| 12 | #import "PNScatterChartData.h" | 13 | #import "PNScatterChartData.h" |
| 13 | #import "PNScatterChartDataItem.h" | 14 | #import "PNScatterChartDataItem.h" |
| 14 | 15 | ||
| 15 | -@interface PNScatterChart : UIView | 16 | +@interface PNScatterChart : PNGenericChart |
| 16 | 17 | ||
| 17 | @property (nonatomic, retain) id<PNChartDelegate> delegate; | 18 | @property (nonatomic, retain) id<PNChartDelegate> delegate; |
| 18 | 19 |
| @@ -44,6 +44,7 @@ | @@ -44,6 +44,7 @@ | ||
| 44 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA23B0F184A5944002DBBA4 /* PCChartsTableViewController.m */; }; | 44 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA23B0F184A5944002DBBA4 /* PCChartsTableViewController.m */; }; |
| 45 | 9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE9190BB014004129F5 /* PNChartLabel.m */; }; | 45 | 9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE9190BB014004129F5 /* PNChartLabel.m */; }; |
| 46 | 9FE15DFA190BB014004129F5 /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DEE190BB014004129F5 /* PNColor.m */; }; | 46 | 9FE15DFA190BB014004129F5 /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DEE190BB014004129F5 /* PNColor.m */; }; |
| 47 | + A9C75FA61A9F1DA900A54638 /* PNGenericChart.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */; }; | ||
| 47 | E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; }; | 48 | E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; }; |
| 48 | /* End PBXBuildFile section */ | 49 | /* End PBXBuildFile section */ |
| 49 | 50 | ||
| @@ -110,6 +111,8 @@ | @@ -110,6 +111,8 @@ | ||
| 110 | 9FE15DE9190BB014004129F5 /* PNChartLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNChartLabel.m; sourceTree = "<group>"; }; | 111 | 9FE15DE9190BB014004129F5 /* PNChartLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNChartLabel.m; sourceTree = "<group>"; }; |
| 111 | 9FE15DED190BB014004129F5 /* PNColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNColor.h; sourceTree = "<group>"; }; | 112 | 9FE15DED190BB014004129F5 /* PNColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNColor.h; sourceTree = "<group>"; }; |
| 112 | 9FE15DEE190BB014004129F5 /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNColor.m; sourceTree = "<group>"; }; | 113 | 9FE15DEE190BB014004129F5 /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNColor.m; sourceTree = "<group>"; }; |
| 114 | + A9C75FA41A9F1DA900A54638 /* PNGenericChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNGenericChart.h; sourceTree = "<group>"; }; | ||
| 115 | + A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNGenericChart.m; sourceTree = "<group>"; }; | ||
| 113 | EFE4F6360943ED4001072124 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; }; | 116 | EFE4F6360943ED4001072124 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; }; |
| 114 | /* End PBXFileReference section */ | 117 | /* End PBXFileReference section */ |
| 115 | 118 | ||
| @@ -266,6 +269,8 @@ | @@ -266,6 +269,8 @@ | ||
| 266 | 91177ED5198DFAC400017E27 /* PNPieChart.m */, | 269 | 91177ED5198DFAC400017E27 /* PNPieChart.m */, |
| 267 | 91177ED6198DFAC400017E27 /* PNPieChartDataItem.h */, | 270 | 91177ED6198DFAC400017E27 /* PNPieChartDataItem.h */, |
| 268 | 91177ED7198DFAC400017E27 /* PNPieChartDataItem.m */, | 271 | 91177ED7198DFAC400017E27 /* PNPieChartDataItem.m */, |
| 272 | + A9C75FA41A9F1DA900A54638 /* PNGenericChart.h */, | ||
| 273 | + A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */, | ||
| 269 | ); | 274 | ); |
| 270 | path = PNChart; | 275 | path = PNChart; |
| 271 | sourceTree = "<group>"; | 276 | sourceTree = "<group>"; |
| @@ -411,6 +416,7 @@ | @@ -411,6 +416,7 @@ | ||
| 411 | 91177EE2198DFAC400017E27 /* PNLineChartDataItem.m in Sources */, | 416 | 91177EE2198DFAC400017E27 /* PNLineChartDataItem.m in Sources */, |
| 412 | 0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */, | 417 | 0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */, |
| 413 | 0A29228A1A423FB300A42BC4 /* PNScatterChartDataItem.m in Sources */, | 418 | 0A29228A1A423FB300A42BC4 /* PNScatterChartDataItem.m in Sources */, |
| 419 | + A9C75FA61A9F1DA900A54638 /* PNGenericChart.m in Sources */, | ||
| 414 | 91177EDA198DFAC400017E27 /* PNBarChart.m in Sources */, | 420 | 91177EDA198DFAC400017E27 /* PNBarChart.m in Sources */, |
| 415 | 91177EE6198DFAC400017E27 /* PNPieChartDataItem.m in Sources */, | 421 | 91177EE6198DFAC400017E27 /* PNPieChartDataItem.m in Sources */, |
| 416 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */, | 422 | 9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */, |
| @@ -34,6 +34,7 @@ | @@ -34,6 +34,7 @@ | ||
| 34 | // Line Chart #1 | 34 | // Line Chart #1 |
| 35 | NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2]; | 35 | NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2]; |
| 36 | PNLineChartData *data01 = [PNLineChartData new]; | 36 | PNLineChartData *data01 = [PNLineChartData new]; |
| 37 | + data01.dataTitle = @"Alpha"; | ||
| 37 | data01.color = PNFreshGreen; | 38 | data01.color = PNFreshGreen; |
| 38 | data01.alpha = 0.3f; | 39 | data01.alpha = 0.3f; |
| 39 | data01.itemCount = data01Array.count; | 40 | data01.itemCount = data01Array.count; |
| @@ -46,6 +47,7 @@ | @@ -46,6 +47,7 @@ | ||
| 46 | // Line Chart #2 | 47 | // Line Chart #2 |
| 47 | NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2]; | 48 | NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2]; |
| 48 | PNLineChartData *data02 = [PNLineChartData new]; | 49 | PNLineChartData *data02 = [PNLineChartData new]; |
| 50 | + data02.dataTitle = @"Beta"; | ||
| 49 | data02.color = PNTwitterColor; | 51 | data02.color = PNTwitterColor; |
| 50 | data02.alpha = 0.5f; | 52 | data02.alpha = 0.5f; |
| 51 | data02.itemCount = data02Array.count; | 53 | data02.itemCount = data02Array.count; |
| @@ -61,6 +63,9 @@ | @@ -61,6 +63,9 @@ | ||
| 61 | 63 | ||
| 62 | 64 | ||
| 63 | [self.view addSubview:self.lineChart]; | 65 | [self.view addSubview:self.lineChart]; |
| 66 | + self.lineChart.legendStyle = PNLegendItemStyleSerial; | ||
| 67 | + self.lineChart.legendFontSize = 17.0; | ||
| 68 | + [self.view addSubview:[self.lineChart getLegendWithMaxWidth:200]]; | ||
| 64 | } | 69 | } |
| 65 | else if ([self.title isEqualToString:@"Bar Chart"]) | 70 | else if ([self.title isEqualToString:@"Bar Chart"]) |
| 66 | { | 71 | { |
-
Please register or login to post a comment