From eb21b73cbde5df7a04f0110b6e53ce98b647aeab Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 08:59:59 -0700 Subject: [PATCH 1/8] 4-22 --- ZFChartView/ZFChartView.xcodeproj/project.pbxproj | 2 ++ ZFChartView/ZFChartView/Base.lproj/Main.storyboard | 10 +++++++--- .../ViewController/SingleBarChartViewController.m | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ZFChartView/ZFChartView.xcodeproj/project.pbxproj b/ZFChartView/ZFChartView.xcodeproj/project.pbxproj index 6b965e0..0b110ae 100644 --- a/ZFChartView/ZFChartView.xcodeproj/project.pbxproj +++ b/ZFChartView/ZFChartView.xcodeproj/project.pbxproj @@ -674,6 +674,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ZFChartView/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Zirkfied.ZFChartView; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -685,6 +686,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ZFChartView/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Zirkfied.ZFChartView; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/ZFChartView/ZFChartView/Base.lproj/Main.storyboard b/ZFChartView/ZFChartView/Base.lproj/Main.storyboard index 9c797d8..c1fa838 100644 --- a/ZFChartView/ZFChartView/Base.lproj/Main.storyboard +++ b/ZFChartView/ZFChartView/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -12,15 +12,18 @@ + - + + + @@ -42,6 +45,7 @@ + diff --git a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m index b2f9c1a..120bb37 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m @@ -29,13 +29,16 @@ - (void)viewDidLoad { // barChart.valueLabelPattern = kPopoverLabelPatternBlank; // barChart.isShowSeparate = YES; [self.view addSubview:barChart]; + + + [barChart strokePath]; } #pragma mark - ZFGenericChartDataSource - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"123", @"256", @"300", @"283", @"490", @"236"]; + return @[@"2", @"4", @"6", @"8", @"9", @"12"]; } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ @@ -47,7 +50,7 @@ - (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{ } - (CGFloat)yLineMaxValueInGenericChart:(ZFGenericChart *)chart{ - return 500; + return 12; } - (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{ From d3759132fae1ba844b2bd7f160b3843c955a933b Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 10:17:44 -0700 Subject: [PATCH 2/8] 1 --- .../SingleBarChartViewController.m | 14 ++++++++------ ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h | 2 ++ .../ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m | 2 ++ .../ZFChart/ZFGenericAxis/ZFGenericAxis.m | 17 ++++++++++++----- .../ZFChart/ZFGenericAxis/ZFXAxisLine.m | 6 ++++-- .../ZFChart/ZFGenericAxis/ZFYAxisLine.m | 11 ++++++++--- .../ZFChart/ZFLineChart/ZFLineChart.m | 1 + .../ZFChart/ZFWaveChart/ZFWaveChart.m | 6 ++++++ 8 files changed, 43 insertions(+), 16 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m index 120bb37..dbeaa06 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m @@ -21,13 +21,15 @@ - (void)viewDidLoad { ZFBarChart * barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)]; barChart.dataSource = self; barChart.delegate = self; - barChart.topic = @"xx小学各年级人数"; - barChart.unit = @"人"; - barChart.topicColor = ZFPurple; + barChart.topic = @"最高年化收益率"; + barChart.unit = @"年收益率(%)"; + barChart.topicColor = ZFOrange; + barChart.isShadow = NO; // barChart.isShowXLineValue = NO; -// barChart.backgroundColor = ZFGreen; -// barChart.valueLabelPattern = kPopoverLabelPatternBlank; + // barChart.backgroundColor = ZFGreen; + barChart.valueLabelPattern = kPopoverLabelPatternPopover; // barChart.isShowSeparate = YES; + // barChart.overMaxValueBarColor = [UIColor orangeColor]; [self.view addSubview:barChart]; @@ -42,7 +44,7 @@ - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"]; + return @[@"7天", @"3个月", @"6个月", @"1年", @"2年", @"3年"]; } - (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{ diff --git a/ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h b/ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h index 49d78cf..a4c145e 100644 --- a/ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h +++ b/ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h @@ -15,6 +15,8 @@ #define ZFClear [UIColor clearColor] #define ZFSkyBlue [UIColor colorWithRed:0 green:0.68 blue:1 alpha:1] +#define ZFZhuClolor ZFColor(178, 179, 181, 1) + /** * 直接填写小数 */ diff --git a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m index f6c8e8d..891c519 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m @@ -110,6 +110,8 @@ - (void)drawBar:(NSMutableArray *)valueArray{ if ([self.genericAxis.xLineValueArray[i] floatValue] / self.genericAxis.yLineMaxValue <= 1) { bar.percent = [self.genericAxis.xLineValueArray[i] floatValue] / self.genericAxis.yLineMaxValue; bar.barColor = _colorArray.firstObject; + //修改 bar 颜色 + bar.barColor = [UIColor orangeColor]; }else{ bar.percent = 1.f; bar.barColor = _overMaxValueBarColor; diff --git a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m index 71ef2de..6fa94ee 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m @@ -74,12 +74,14 @@ - (instancetype)initWithFrame:(CGRect)frame{ - (void)drawAxisLine{ //x轴 self.xAxisLine = [[ZFXAxisLine alloc] initWithFrame:self.bounds]; - self.xAxisLine.backgroundColor = _axisLineBackgroundColor; + self.xAxisLine.backgroundColor = _axisLineBackgroundColor;// [self addSubview:self.xAxisLine]; //y轴 self.yAxisLine = [[ZFYAxisLine alloc] initWithFrame:CGRectMake(0, 0, ZFAxisLineStartXPos/* + YLineSectionLength*/, self.bounds.size.height)]; self.yAxisLine.backgroundColor = _axisLineBackgroundColor; + // self.yAxisLine.backgroundColor = [UIColor redColor]; + self.yAxisLine.alpha = 1; [self addSubview:self.yAxisLine]; } @@ -92,14 +94,16 @@ - (void)drawAxisLine{ - (void)addUnitLabel{ ZFLabel * lastLabel = (ZFLabel *)[self.yAxisLine viewWithTag:YLineValueLabelTag + _yLineSectionCount]; - CGFloat width = self.yAxisLine.yLineStartXPos; + + CGFloat width = self.yAxisLine.yLineStartXPos +20 ; + CGFloat height = self.yAxisLine.yLineSectionHeightAverage; CGFloat xPos = 0; CGFloat yPos = CGRectGetMinY(lastLabel.frame) - height; self.unitLabel = [[ZFLabel alloc] initWithFrame:CGRectMake(xPos, yPos, width, height)]; - self.unitLabel.text = [NSString stringWithFormat:@"(%@)",_unit]; - self.unitLabel.font = [UIFont boldSystemFontOfSize:10]; + self.unitLabel.text = [NSString stringWithFormat:@"%@",_unit]; + self.unitLabel.font = [UIFont systemFontOfSize:10]; [self.yAxisLine addSubview:self.unitLabel]; } @@ -209,7 +213,10 @@ - (CAShapeLayer *)yAxisLineSectionShapeLayer:(NSInteger)i sectionLength:(CGFloat - (UIView *)sectionView:(NSInteger)i{ CGFloat yStartPos = self.yAxisLine.yLineStartYPos - (self.yAxisLine.yLineHeight - ZFAxisLineGapFromYLineMaxValueToArrow) / _yLineSectionCount * (i + 1); UIView * view = [[UIView alloc] initWithFrame:CGRectMake(self.yAxisLine.yLineStartXPos, yStartPos, YLineSectionLength, YLineSectionHeight)]; - view.backgroundColor = ZFBlack; + // + view.backgroundColor = ZFZhuClolor; + // view.backgroundColor = [UIColor redColor]; + view.alpha = 0.f; _sectionOriginX = view.frame.origin.x; diff --git a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFXAxisLine.m b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFXAxisLine.m index 2cf363e..c75783a 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFXAxisLine.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFXAxisLine.m @@ -84,7 +84,8 @@ - (UIBezierPath *)drawXAxisLine{ */ - (CAShapeLayer *)xAxisLineShapeLayer{ CAShapeLayer * xAxisLineLayer = [CAShapeLayer layer]; - xAxisLineLayer.fillColor = [UIColor blackColor].CGColor; + //x轴颜色 + xAxisLineLayer.fillColor = ZFZhuClolor.CGColor; xAxisLineLayer.path = [self drawXAxisLine].CGPath; CABasicAnimation * animation = [self animationFromValue:[self axisLineNoFill] toValue:[self drawXAxisLine]]; @@ -132,7 +133,8 @@ - (UIBezierPath *)drawArrows{ */ - (CAShapeLayer *)arrowsShapeLayer{ CAShapeLayer * arrowsLayer = [CAShapeLayer layer]; - arrowsLayer.fillColor = [UIColor blackColor].CGColor; + //箭头 颜色 + arrowsLayer.fillColor = [UIColor grayColor].CGColor; arrowsLayer.path = [self drawArrows].CGPath; CABasicAnimation * animation = [self animationFromValue:[self arrowsNoFill] toValue:[self drawArrows]]; diff --git a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFYAxisLine.m b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFYAxisLine.m index 4ed6be1..0153b6f 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFYAxisLine.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFYAxisLine.m @@ -46,7 +46,10 @@ - (void)commonInit{ _arrowsWidthHalf = _arrowsWidth / 2.f; _lineWidthHalf = _yLineWidth / 2.f; _sectionLength = YLineSectionLength; - _sectionColor = ZFBlack; + + // _sectionColor = ZFBlack; + _sectionColor = [UIColor redColor]; + } - (instancetype)initWithFrame:(CGRect)frame{ @@ -88,7 +91,8 @@ - (UIBezierPath *)drawYAxisLine{ */ - (CAShapeLayer *)yAxisLineShapeLayer{ CAShapeLayer * yAxisLineLayer = [CAShapeLayer layer]; - yAxisLineLayer.fillColor = [UIColor blackColor].CGColor; + //y轴 颜色 + yAxisLineLayer.fillColor = ZFZhuClolor.CGColor; yAxisLineLayer.path = [self drawYAxisLine].CGPath; CABasicAnimation * animation = [self animationFromValue:[self axisLineNoFill] toValue:[self drawYAxisLine] duration:_animationDuration]; @@ -137,7 +141,8 @@ - (UIBezierPath *)drawArrows{ */ - (CAShapeLayer *)arrowsShapeLayer{ CAShapeLayer * arrowsLayer = [CAShapeLayer layer]; - arrowsLayer.fillColor = [UIColor blackColor].CGColor; + //y箭头颜色 + arrowsLayer.fillColor = [UIColor grayColor].CGColor; arrowsLayer.path = [self drawArrows].CGPath; CABasicAnimation * animation = [self animationFromValue:[self arrowsNoFill] toValue:[self drawArrows] duration:_animationDuration]; diff --git a/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m b/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m index 400decc..bd08310 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m @@ -416,6 +416,7 @@ - (void)setIsShowSeparate:(BOOL)isShowSeparate{ _isShowSeparate = isShowSeparate; self.genericAxis.isShowSeparate = _isShowSeparate; self.genericAxis.sectionColor = ZFLightGray; + } @end diff --git a/ZFChartView/ZFChartView/ZFChart/ZFWaveChart/ZFWaveChart.m b/ZFChartView/ZFChartView/ZFChart/ZFWaveChart/ZFWaveChart.m index 267c463..2a08b9d 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFWaveChart/ZFWaveChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFWaveChart/ZFWaveChart.m @@ -34,6 +34,7 @@ - (void)commonInit{ _valueOnChartFontSize = 10.f; _valueLabelPattern = kPopoverLabelPatternPopover; _valueTextColor = ZFBlack; + _overMaxValueTextColor = ZFRed; _unit = @""; _isShadowForValueLabel = YES; @@ -70,7 +71,9 @@ - (void)drawGenericChart{ - (void)drawWavePath{ self.wave = [[ZFWave alloc] initWithFrame:CGRectMake(self.genericAxis.axisStartXPos, self.genericAxis.yLineMaxValueYPos, self.genericAxis.xLineWidth, self.genericAxis.yLineMaxValueHeight)]; self.wave.valuePointArray = _valuePointArray; + self.wave.pathColor = _pathColor; + self.wave.padding = self.genericAxis.groupPadding; self.wave.wavePatternType = _wavePatternType; [self.genericAxis addSubview:self.wave]; @@ -270,6 +273,9 @@ - (void)setIsShowSeparate:(BOOL)isShowSeparate{ _isShowSeparate = isShowSeparate; self.genericAxis.isShowSeparate = _isShowSeparate; self.genericAxis.sectionColor = ZFLightGray; + + // self.genericAxis.sectionColor = [UIColor redColor]; + } @end From 6ff1866809fdf5ac4403021966e3bf23b29c0e1e Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 11:10:34 -0700 Subject: [PATCH 3/8] 2 --- .../ViewController/SingleBarChartViewController.m | 6 +++--- ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m | 5 +++-- .../ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m index dbeaa06..50667e0 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m @@ -18,7 +18,7 @@ @implementation SingleBarChartViewController - (void)viewDidLoad { [super viewDidLoad]; - ZFBarChart * barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)]; + ZFBarChart * barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT/2)]; barChart.dataSource = self; barChart.delegate = self; barChart.topic = @"最高年化收益率"; @@ -40,7 +40,7 @@ - (void)viewDidLoad { #pragma mark - ZFGenericChartDataSource - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"2", @"4", @"6", @"8", @"9", @"12"]; + return @[@"2", @"3", @"4", @"5", @"6", @"7"]; } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ @@ -52,7 +52,7 @@ - (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{ } - (CGFloat)yLineMaxValueInGenericChart:(ZFGenericChart *)chart{ - return 12; + return 8; } - (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{ diff --git a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m index 891c519..89a9b79 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m @@ -70,8 +70,9 @@ - (instancetype)initWithFrame:(CGRect)frame{ [self drawGenericChart]; //标题Label - self.topicLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)]; - self.topicLabel.font = [UIFont boldSystemFontOfSize:18.f]; + self.topicLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width/4 ,0, self.frame.size.width/2, 30)]; + self.topicLabel.font = [UIFont boldSystemFontOfSize:16.f]; + self.topicLabel.backgroundColor = [UIColor cyanColor]; self.topicLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:self.topicLabel]; } diff --git a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m index 6fa94ee..6e7a90c 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m @@ -101,7 +101,7 @@ - (void)addUnitLabel{ CGFloat xPos = 0; CGFloat yPos = CGRectGetMinY(lastLabel.frame) - height; - self.unitLabel = [[ZFLabel alloc] initWithFrame:CGRectMake(xPos, yPos, width, height)]; + self.unitLabel = [[ZFLabel alloc] initWithFrame:CGRectMake(xPos, yPos -20, width, height)]; self.unitLabel.text = [NSString stringWithFormat:@"%@",_unit]; self.unitLabel.font = [UIFont systemFontOfSize:10]; [self.yAxisLine addSubview:self.unitLabel]; From 68481c0243f5905762759a47272aa0fcefbf21c4 Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 11:15:45 -0700 Subject: [PATCH 4/8] 3 --- .../ViewController/SingleBarChartViewController.m | 5 ++--- .../ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m index 50667e0..316a298 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m @@ -32,8 +32,7 @@ - (void)viewDidLoad { // barChart.overMaxValueBarColor = [UIColor orangeColor]; [self.view addSubview:barChart]; - - + [barChart strokePath]; } @@ -44,7 +43,7 @@ - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"7天", @"3个月", @"6个月", @"1年", @"2年", @"3年"]; + return @[@"7天", @"3个月", @"6个月", @"一年", @"二年", @"三年"]; } - (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{ diff --git a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m index 6e7a90c..da81338 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m @@ -110,7 +110,7 @@ - (void)addUnitLabel{ #pragma mark - 设置x轴标题Label /** - * 设置x轴标题Label + * 设置x轴标题Label x */ - (void)setXLineNameLabel{ if (self.xLineNameArray.count > 0) { @@ -118,7 +118,7 @@ - (void)setXLineNameLabel{ CGFloat width = _groupWidth; CGFloat height = _xLineLabelHeight; CGFloat center_xPos = self.xAxisLine.xLineStartXPos + _groupPadding + (_groupWidth + _groupPadding) * i + width * 0.5; - CGFloat center_yPos = self.yAxisLine.yLineStartYPos + 20 + height * 0.5; + CGFloat center_yPos = self.yAxisLine.yLineStartYPos + height * 0.5; //label的中心点 CGPoint label_center = CGPointMake(center_xPos, center_yPos); @@ -128,6 +128,7 @@ - (void)setXLineNameLabel{ label.font = [UIFont systemFontOfSize:_xLineNameFontSize]; label.numberOfLines = 0; label.center = label_center; + label.backgroundColor = [UIColor cyanColor]; [self.xAxisLine addSubview:label]; } } From bc6471bad696cc75b18a14a381432226d35a9e42 Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 13:40:59 -0700 Subject: [PATCH 5/8] no message --- .../ViewController/SingleBarChartViewController.m | 8 +++++--- ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m index 316a298..6cc1fee 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleBarChartViewController.m @@ -28,7 +28,8 @@ - (void)viewDidLoad { // barChart.isShowXLineValue = NO; // barChart.backgroundColor = ZFGreen; barChart.valueLabelPattern = kPopoverLabelPatternPopover; -// barChart.isShowSeparate = YES; + //isShadowForValueLabel + barChart.isShadowForValueLabel = NO; // barChart.overMaxValueBarColor = [UIColor orangeColor]; [self.view addSubview:barChart]; @@ -39,7 +40,7 @@ - (void)viewDidLoad { #pragma mark - ZFGenericChartDataSource - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"2", @"3", @"4", @"5", @"6", @"7"]; + return @[@"2.01", @"3.02", @"4.03", @"5.11", @"6.50", @"7.7"]; } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ @@ -55,7 +56,7 @@ - (CGFloat)yLineMaxValueInGenericChart:(ZFGenericChart *)chart{ } - (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{ - return 10; + return 4; } #pragma mark - ZFBarChartDelegate @@ -74,6 +75,7 @@ - (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{ - (void)barChart:(ZFBarChart *)barChart didSelectBarAtGroupIndex:(NSInteger)groupIndex barIndex:(NSInteger)barIndex{ NSLog(@"第%ld组========第%ld个",(long)groupIndex,(long)barIndex); + } - (void)barChart:(ZFBarChart *)barChart didSelectPopoverLabelAtGroupIndex:(NSInteger)groupIndex labelIndex:(NSInteger)labelIndex{ diff --git a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m index 89a9b79..f3f86a0 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m @@ -104,7 +104,7 @@ - (void)drawBar:(NSMutableArray *)valueArray{ CGFloat width = _barWidth; CGFloat height = self.genericAxis.yLineMaxValueHeight; - ZFBar * bar = [[ZFBar alloc] initWithFrame:CGRectMake(xPos, yPos, width, height)]; + ZFBar * bar = [[ZFBar alloc] initWithFrame:CGRectMake(xPos, yPos, width*2/3, height)]; bar.groupAtIndex = 0; bar.barIndex = i; //当前数值超过y轴显示上限时,柱状改为红色 @@ -210,6 +210,8 @@ - (void)setValueLabelOnChart:(NSMutableArray *)valueArray{ popoverLabel.groupIndex = groupIndex; popoverLabel.labelIndex = barIndex; [popoverLabel strokePath]; + popoverLabel.backgroundColor = [UIColor cyanColor]; + [self.genericAxis addSubview:popoverLabel]; [popoverLabel addTarget:self action:@selector(popoverAction:) forControlEvents:UIControlEventTouchUpInside]; } From d4f64b8eac347a037646afa4ac5008260e9340f5 Mon Sep 17 00:00:00 2001 From: xinruan Date: Fri, 22 Apr 2016 14:44:12 -0700 Subject: [PATCH 6/8] =?UTF-8?q?=E9=92=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SingleLineChartViewController.m | 11 +++++++---- .../ZFChart/ZFLineChart/ZFLineChart.m | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/SingleLineChartViewController.m b/ZFChartView/ZFChartView/ViewController/SingleLineChartViewController.m index 5359c43..f831570 100644 --- a/ZFChartView/ZFChartView/ViewController/SingleLineChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/SingleLineChartViewController.m @@ -21,12 +21,15 @@ - (void)viewDidLoad { ZFLineChart * lineChart = [[ZFLineChart alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)]; lineChart.dataSource = self; lineChart.delegate = self; - lineChart.topic = @"xx小学各年级男女人数"; - lineChart.unit = @"人"; + lineChart.topic = @"近一个月涨跌幅-20.66%"; + lineChart.unit = @""; lineChart.topicColor = ZFPurple; // lineChart.backgroundColor = ZFGreen; // lineChart.valueLabelPattern = kPopoverLabelPatternBlank; -// lineChart.isShowSeparate = YES; + lineChart.isShowSeparate = YES; + lineChart.isShadow = NO; + lineChart.isShadowForValueLabel = NO; + [self.view addSubview:lineChart]; [lineChart strokePath]; } @@ -34,7 +37,7 @@ - (void)viewDidLoad { #pragma mark - ZFGenericChartDataSource - (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{ - return @[@"123", @"256", @"300", @"283", @"490", @"236"]; + return @[@"123", @"256", @"300", @"283", @"490", @"236",@"23",@"34",@"55",@"45",@"66" ]; } - (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{ diff --git a/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m b/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m index bd08310..7463d16 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFLineChart/ZFLineChart.m @@ -75,6 +75,7 @@ - (instancetype)initWithFrame:(CGRect)frame{ */ - (void)drawGenericChart{ self.genericAxis = [[ZFGenericAxis alloc] initWithFrame:self.bounds]; + [self addSubview:self.genericAxis]; } @@ -105,7 +106,10 @@ - (void)drawCircle{ circle.circleColor = isOverrun ? _overMaxValueCircleColor : _colorArray.firstObject; circle.isShadow = _isShadow; [circle strokePath]; - [self.genericAxis addSubview:circle]; + + //暂时屏蔽 + //[self.genericAxis addSubview:circle]; + [self.circleArray addObject:circle]; [circle addTarget:self action:@selector(circleAction:) forControlEvents:UIControlEventTouchUpInside]; @@ -137,6 +141,7 @@ - (void)drawCircle{ circle.isShadow = _isShadow; [circle strokePath]; [self.genericAxis addSubview:circle]; + [subArray addObject:circle]; [circle addTarget:self action:@selector(circleAction:) forControlEvents:UIControlEventTouchUpInside]; @@ -188,7 +193,11 @@ - (void)addValueLabel:(NSMutableArray *)circleArray index:(NSInteger)index color popoverLabel.isShadow = _isShadowForValueLabel; popoverLabel.groupIndex = colorIndex; popoverLabel.labelIndex = index; - [self.genericAxis addSubview:popoverLabel]; + + //暂时屏蔽 + //[self.genericAxis addSubview:popoverLabel]; + + [popoverLabel addTarget:self action:@selector(popoverAction:) forControlEvents:UIControlEventTouchUpInside]; //_valueOnChartPosition为上下分布 @@ -373,7 +382,10 @@ - (void)strokePath{ [self removeLabelOnChart]; [self removeAllSubLayer]; [self.genericAxis strokePath]; + + //暂时屏蔽 [self drawCircle]; + [self drawLine]; _isShowXLineValue ? [self setValueLabelOnChart] : nil; [self.genericAxis bringSubviewToFront:self.genericAxis.yAxisLine]; From 944f683f8ade0ca25a06a9fbc72e75f0f437f92f Mon Sep 17 00:00:00 2001 From: xinruan Date: Thu, 19 May 2016 16:02:23 -0700 Subject: [PATCH 7/8] 1 --- .../ViewController/PieChartViewController.m | 46 +- .../ZFChartView/ZFChart/ZFPieChart/ZFPie.m | 7 +- .../ZFChart/ZFPieChart/ZFPieChart.h | 67 +-- .../ZFChart/ZFPieChart/ZFPieChart.m | 531 ++++++++++-------- 4 files changed, 346 insertions(+), 305 deletions(-) diff --git a/ZFChartView/ZFChartView/ViewController/PieChartViewController.m b/ZFChartView/ZFChartView/ViewController/PieChartViewController.m index 735bce2..7858745 100644 --- a/ZFChartView/ZFChartView/ViewController/PieChartViewController.m +++ b/ZFChartView/ZFChartView/ViewController/PieChartViewController.m @@ -7,9 +7,13 @@ // #import "PieChartViewController.h" + #import "ZFChart.h" -@interface PieChartViewController() +@interface PieChartViewController() +{ + ZFPieChart *pieChart; +} @end @@ -18,29 +22,31 @@ @implementation PieChartViewController - (void)viewDidLoad{ [super viewDidLoad]; - ZFPieChart * pieChart = [[ZFPieChart alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)]; - pieChart.dataSource = self; -// pieChart.piePatternType = kPieChartPatternTypeForCircle; -// pieChart.percentType = kPercentTypeInteger; -// pieChart.isShadow = NO; - pieChart.isShowDetail = YES; - pieChart.topic = @"xx小学各年级男女人数占比"; - [pieChart strokePath]; + pieChart = [[ZFPieChart alloc] initWithFrame:CGRectMake(0, 80 ,410, 180)]; + pieChart.backgroundColor = [UIColor colorWithWhite:0.97 alpha:0.9]; + pieChart.lineWidth = 20.0; + // pieChart.allMoneyLabel.text = @"总资产(元):502.10"; + pieChart.isShowPercent = NO; //不现实百分比 + pieChart.valueArray = [NSMutableArray arrayWithObjects:@12, @23, @44, @88, nil ];//金额 调用setter方法 + pieChart.nameArray = [NSMutableArray arrayWithObjects:@"名字1", @"名字2",@"名字3",@"名字4",nil]; + pieChart.colorArray = [NSMutableArray arrayWithObjects:[UIColor yellowColor], [UIColor redColor],[UIColor greenColor], [UIColor purpleColor], nil];// 颜色 [self.view addSubview:pieChart]; + //绘制 + [pieChart strokePath]; } #pragma mark - ZFPieChartDataSource -- (NSArray *)valueArrayInPieChart:(ZFPieChart *)chart{ - return @[@"200", @"256", @"300", @"283", @"490", @"236"]; -} - -- (NSArray *)nameArrayInPieChart:(ZFPieChart *)chart{ - return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"]; -} - -- (NSArray *)colorArrayInPieChart:(ZFPieChart *)chart{ - return @[ZFColor(71, 204, 255, 1), ZFColor(253, 203, 76, 1), ZFColor(214, 205, 153, 1), ZFColor(78, 250, 188, 1), ZFColor(16, 140, 39, 1), ZFColor(45, 92, 34, 1)]; -} +//- (NSArray *)valueArrayInPieChart:(ZFPieChart *)chart{ +// return @[@"200", @"256", @"300", @"283", @"490", @"236"]; +//} +// +//- (NSArray *)nameArrayInPieChart:(ZFPieChart *)chart{ +// return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"]; +//} +// +//- (NSArray *)colorArrayInPieChart:(ZFPieChart *)chart{ +// return @[ZFColor(71, 204, 255, 1), ZFColor(253, 203, 76, 1), ZFColor(214, 205, 153, 1), ZFColor(78, 250, 188, 1), ZFColor(16, 140, 39, 1), ZFColor(45, 92, 34, 1)]; +//} @end diff --git a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPie.m b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPie.m index fb63368..551ff45 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPie.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPie.m @@ -27,7 +27,12 @@ - (instancetype)initWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle self.path = [self bezierWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle color:color].CGPath; if (piePatternType == kPieChartPatternTypeForCirque) { - self.lineWidth = radius; + + //圆环宽度518 + //mxt518 + // self.lineWidth = radius; + self.lineWidth = 30; + }else if (piePatternType == kPieChartPatternTypeForCircle){ self.lineWidth = radius * 2; } diff --git a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.h b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.h index 474631e..f1b867c 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.h +++ b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.h @@ -2,46 +2,11 @@ // ZFPieChart.h // ZFChartView // -// Created by apple on 16/3/21. +// Created by apple on 16/2/16. // Copyright © 2016年 apple. All rights reserved. // #import -#import "ZFPie.h" -@class ZFPieChart; - -/********************* ZFPieChartDataSource(ZFPieChart数据源方法) *********************/ -@protocol ZFPieChartDataSource - -@required -/** - * value数据 - * - * @return NSArray必须存储NSString类型 - */ -- (NSArray *)valueArrayInPieChart:(ZFPieChart *)chart; - -/** - * 颜色数组 - * - * @return NSArray必须存储UIColor类型 - */ -- (NSArray *)colorArrayInPieChart:(ZFPieChart *)chart; - - - -@optional -/** - * 名称数据 - * - * @return NSArray必须存储NSString类型 - */ -- (NSArray *)nameArrayInPieChart:(ZFPieChart *)chart; - -@end - - - typedef enum{ /** @@ -54,26 +19,30 @@ typedef enum{ kPercentTypeInteger = 1 }kPercentType; -@interface ZFPieChart : UIScrollView - -@property (nonatomic, weak) id dataSource; +@interface ZFPieChart : UIView -/** 主题 */ -@property (nonatomic, copy) NSString * topic; -/** 饼图样式(若不设置,默认为kPieChartPatternTypeForCirque(圆环样式)) */ -@property (nonatomic, assign) kPiePatternType piePatternType; +/** 标题 */ +@property (nonatomic, copy) NSString * title; +/** 数值数组 (存储的是NSString类型) */ +@property (nonatomic, strong) NSMutableArray * valueArray; +/** 名字数组 (存储的是NSString类型) */ +@property (nonatomic, strong) NSMutableArray * nameArray; +/** 颜色数组 (存储的是UIColor类型) */ +@property (nonatomic, strong) NSMutableArray * colorArray; /** kPercentType类型 */ @property (nonatomic, assign) kPercentType percentType; +/** 显示详细信息(默认为YES) */ +@property (nonatomic, assign) BOOL isShowDetail; /** 显示百分比(默认为YES) */ @property (nonatomic, assign) BOOL isShowPercent; -/** 图表上百分比字体大小 */ -@property (nonatomic, assign) CGFloat percentOnChartFontSize; -/** 是否带阴影效果(默认为YES) */ -@property (nonatomic, assign) BOOL isShadow; -/** 显示详细信息(默认为NO) */ -@property (nonatomic, assign) BOOL isShowDetail; + + +//yg +/** 圆环线宽 */ +@property (nonatomic, assign) CGFloat lineWidth; + #pragma mark - public method /** diff --git a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.m b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.m index 98fc20c..6196251 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.m @@ -2,81 +2,64 @@ // ZFPieChart.m // ZFChartView // -// Created by apple on 16/3/21. +// Created by apple on 16/2/16. // Copyright © 2016年 apple. All rights reserved. // #import "ZFPieChart.h" -#import "ZFPie.h" #import "ZFConst.h" +//#import "NSObject+Zirkfied.h" #import "NSString+Zirkfied.h" +#import "UIColor+Zirkfied.h" #import "UIView+Zirkfied.h" #import "ZFTranslucencePath.h" +#define PercentLabelTag 100 +#define DetailBackgroundTag 500 + @interface ZFPieChart() -/** 存储value的数组 */ -@property (nonatomic, strong) NSMutableArray * valueArray; -/** 存储名称的数组 */ -@property (nonatomic, strong) NSMutableArray * nameArray; -/** 存储颜色的数组 */ -@property (nonatomic, strong) NSMutableArray * colorArray; -/** 存储开始角度的数组 */ -@property (nonatomic, strong) NSMutableArray * startAngleArray; -/** 存储结束角度的数组 */ -@property (nonatomic, strong) NSMutableArray * endAngleArray; -/** 存储每个圆弧动画开始的时间 */ -@property (nonatomic, strong) NSMutableArray * startTimeArray; -/** 动画总时长 */ -@property (nonatomic, assign) CFTimeInterval totalDuration; +/** 总数 */ +@property (nonatomic, assign) CGFloat totalValue; /** 半径 */ @property (nonatomic, assign) CGFloat radius; /** 半径最大上限 */ @property (nonatomic, assign) CGFloat maxRadius; -/** 总数 */ -@property (nonatomic, assign) CGFloat totalValue; /** 记录每个圆弧开始的角度 */ @property (nonatomic, assign) CGFloat startAngle; +/** 动画总时长 */ +@property (nonatomic, assign) CFTimeInterval totalDuration; +///** 圆环线宽 */ +//@property (nonatomic, assign) CGFloat lineWidth; /** 记录valueArray当前元素的下标 */ @property (nonatomic, assign) NSInteger index; /** 记录当前path的中心点 */ @property (nonatomic, assign) CGPoint centerPoint; -/** 记录bezier线宽 */ -@property (nonatomic, assign) CGFloat lineWidth; -/** 记录圆环中心 */ -@property (nonatomic, assign) CGPoint pieCenter; /** 半透明Path延伸长度 */ @property (nonatomic, assign) CGFloat extendLength; -/** 记录self初始高度 */ +/** 记录圆环中心 */ +@property (nonatomic, assign) CGPoint pieCenter; +/** 记录初始高度 */ @property (nonatomic, assign) CGFloat originHeight; - - -/** 主题Label */ -@property (nonatomic, strong) UILabel * topicLabel; +/** 存储每个圆弧动画开始的时间 */ +@property (nonatomic, strong) NSMutableArray * startTimeArray; +/** 记录每个path startAngle 和 endAngle, 数组里存的是NSDictionary */ +@property (nonatomic, strong) NSMutableArray * angelArray; +/** 标题Label */ +@property (nonatomic, strong) UILabel * titleLabel; +/** 数值Label */ +@property (nonatomic, strong) UILabel * valueLabel; @end @implementation ZFPieChart -- (NSMutableArray *)colorArray{ - if (!_colorArray) { - _colorArray = [NSMutableArray array]; - } - return _colorArray; -} -- (NSMutableArray *)startAngleArray{ - if (!_startAngleArray) { - _startAngleArray = [NSMutableArray array]; - } - return _startAngleArray; -} -- (NSMutableArray *)endAngleArray{ - if (!_endAngleArray) { - _endAngleArray = [NSMutableArray array]; - } - return _endAngleArray; +- (void)dispatch_after_withSeconds:(float)seconds actions:(void(^)(void))actions{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + actions(); + }); } - (NSMutableArray *)startTimeArray{ @@ -86,278 +69,240 @@ - (NSMutableArray *)startTimeArray{ return _startTimeArray; } +- (NSMutableArray *)angelArray{ + if (!_angelArray) { + _angelArray = [NSMutableArray array]; + } + return _angelArray; +} + /** - * 初始化属性 + * 初始化变量 */ - (void)commonInit{ _maxRadius = self.frame.size.width > self.frame.size.height ? self.frame.size.height : self.frame.size.width; - _radius = _maxRadius * ZFPieChartCirqueRatio; - _piePatternType = kPieChartPatternTypeForCirque; - _isShadow = YES; - _isShowPercent = YES; - _isShowDetail = NO; - _startAngle = ZFRadian(-90); + _radius = _maxRadius * 0.25; + // _lineWidth = _radius; _totalDuration = 0.75f; - _percentOnChartFontSize = 10.f; - _extendLength = _radius * ZFPieChartCirqueRatio; + _startAngle = ZFRadian(-90); + _extendLength = 5.f; _originHeight = self.frame.size.height; - _pieCenter = CGPointMake(self.center.x, CGRectGetHeight(self.topicLabel.frame) + NAVIGATIONBAR_HEIGHT + _radius); - self.backgroundColor = ZFWhite; - self.bounces = NO; - self.showsHorizontalScrollIndicator = NO; + _pieCenter = CGPointMake(self.frame.size.width / 2-70, self.frame.size.height / 2); + _isShowDetail = YES; + _isShowPercent = YES; } + +# pragma mark - - 初始化 + - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { - //标题Label - self.topicLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)]; - self.topicLabel.font = [UIFont boldSystemFontOfSize:18.f]; - self.topicLabel.textAlignment = NSTextAlignmentCenter; - [self addSubview:self.topicLabel]; + //初始化变量 [self commonInit]; + + //标题Label + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)]; + self.titleLabel.font = [UIFont boldSystemFontOfSize:18.f]; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + self.titleLabel.textColor = [UIColor redColor]; + [self addSubview:self.titleLabel]; + + //数值Label + self.valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _radius, _radius * 0.5)]; + self.valueLabel.font = [UIFont boldSystemFontOfSize:13.f]; + self.valueLabel.textAlignment = NSTextAlignmentCenter; + self.valueLabel.textColor = [UIColor blueColor]; + self.valueLabel.center = self.pieCenter; + [self addSubview:self.valueLabel]; } - return self; } + +# pragma mark - - 添加详情UI /** * 添加详情 */ - (void)addUI{ - for (NSInteger i = 0; i < self.valueArray.count; i++) { - CGFloat height = 25; - CGFloat yPos = _piePatternType == kPieChartPatternTypeForCirque ? _pieCenter.y + _radius * 1.75 + height * i : _pieCenter.y + _radius * 2.4 + height * i; + + CGFloat valuCount = self.valueArray.count; + + for (NSInteger i = 0; i < valuCount; i++) { - //装载容器 - UIView * background = [[UIView alloc] initWithFrame:CGRectMake(0, yPos, self.frame.size.width, height)]; - background.tag = PieChartDetailBackgroundTag + i; + //装载容器self.frame.size.height / 8.f * 7 + 30 + 25 + UIView * background = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width/2, 150-16-16*(valuCount-i-1) , self.frame.size.width, 16)]; + background.tag = DetailBackgroundTag + i; [self addSubview:background]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showTranslucencePathAction:)]; [background addGestureRecognizer:tap]; //颜色View - UIView * color = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, 5, 10, 10)]; - [color setBorderCornerRadius:color.frame.size.width * 0.5 andBorderWidth:0 andBorderColor:nil]; + UIView * color = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, 2, 10, 10)]; color.backgroundColor = _colorArray[i]; [background addSubview:color]; - CGFloat width = (self.frame.size.width * (1 - 0.1) - 40) / 3.f; - CGFloat gap = (SCREEN_WIDTH - CGRectGetMaxX(color.frame) - 10 - self.frame.size.width * 0.05 - 3 * width) / 2; - //名称 - UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(color.frame) + 10, 0, width, 20)]; - name.text = _nameArray[i]; - name.font = [UIFont boldSystemFontOfSize:16.f]; + CGFloat width = (self.frame.size.width * (1 - 0.1) - 40) / 4.f; + UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(color.frame) + 10, 0, width+20, 16)]; + //name.backgroundColor = [UIColor cyanColor]; + NSString *nameString = [NSString stringWithFormat:@"%@(%@)", _nameArray[i], [self getPercent:i]]; + name.text = nameString; + name.textAlignment = NSTextAlignmentLeft; + name.font = [UIFont systemFontOfSize:11]; [background addSubview:name]; - //数值 - UILabel * value = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + gap, 0, width, 20)]; - value.text = _valueArray[i]; - value.font = [UIFont boldSystemFontOfSize:16.f]; - [background addSubview:value]; - - //百分比 - UILabel * percent = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(value.frame) + gap, 0, width, 20)]; - percent.text = [self getPercent:i]; - percent.font = [UIFont boldSystemFontOfSize:16.f]; - [background addSubview:percent]; +// //百分比 +// UILabel * percent = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame), 0, width, 20)]; +// percent.backgroundColor = [UIColor yellowColor]; +// //percent.text = ; +// percent.font = [UIFont systemFontOfSize:12]; +// [background addSubview:percent]; } +} + + + +#pragma mark - Arc(圆弧)UIBezierPath +/** + * 填充 + * @return UIBezierPath + */ +- (UIBezierPath *)fill{ + + //需要多少度的圆弧 + CGFloat angle = [self countAngle:[_valueArray[_index] floatValue]]; + + UIBezierPath * bezier = [UIBezierPath bezierPathWithArcCenter:_pieCenter radius:_radius startAngle:_startAngle endAngle:_startAngle + angle clockwise:YES]; + //获取每个path的中心点 + self.centerPoint = [self getBezierPathCenterPointWithStartAngle:_startAngle endAngle:_startAngle + angle]; + + //记录开始角度和结束角度 + NSDictionary * dict = @{@"startAngle":@(_startAngle), @"endAngle":@(_startAngle + angle)}; + [self.angelArray addObject:dict]; + + _startAngle += angle; - //重设self.frame的值 - UILabel * lastLabel = (UILabel *)[self viewWithTag:PieChartDetailBackgroundTag + self.valueArray.count - 1]; - self.contentSize = CGSizeMake(self.frame.size.width, CGRectGetMaxY(lastLabel.frame) + 20); + return bezier; } + +# pragma mark - -CAShapeLayer /** - * 饼图每部分的shapeLayer - * - * @param center 中心点 - * @param startAngle 开始角度 - * @param endAngle 结束角度 - * @param color 颜色 - * @param duration 动画执行时间 - * @param piePatternType 饼图类型 + * CAShapeLayer * * @return CAShapeLayer */ -- (CAShapeLayer *)pieShapeLayerWithCenter:(CGPoint)center startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle color:(UIColor *)color duration:(CFTimeInterval)duration piePatternType:(kPiePatternType)piePatternType{ +- (CAShapeLayer *)shapeLayer{ + + CAShapeLayer * shapeLayer = [CAShapeLayer layer]; + shapeLayer.fillColor = nil; + shapeLayer.strokeColor = [_colorArray[_index] CGColor]; + //mxt518 + shapeLayer.lineWidth = _lineWidth; + + //第三部 + //3、将bezierPath的CGPath赋值给caShapeLayer的path,即caShapeLayer.path = bezierPath.CGPath + shapeLayer.path = [self fill].CGPath; - ZFPie * pie = [ZFPie pieWithCenter:center radius:_radius startAngle:startAngle endAngle:endAngle color:color duration:duration piePatternType:piePatternType]; - pie.isShadow = _isShadow; - _lineWidth = pie.lineWidth; - return pie; + //动画 + CABasicAnimation * animation = [self animation];//填充动画过程 + + [shapeLayer addAnimation:animation forKey:nil]; + + return shapeLayer; } -#pragma mark - 半透明Path +#pragma mark - 动画 /** - * 半透明Path - * - * @param startAngle 开始角度 - * @param endAngle 结束角度 - * @param index 下标 + * 填充动画过程 * - * @return ZFTranslucencePath + * @return CABasicAnimation */ -- (ZFTranslucencePath *)translucencePathShapeLayerWithStartAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle index:(NSInteger)index{ - ZFTranslucencePath * layer = [ZFTranslucencePath layerWithArcCenter:_pieCenter radius:_radius + _extendLength * 0.5 startAngle:startAngle endAngle:endAngle clockwise:YES]; - layer.strokeColor = [_colorArray[index] CGColor]; - layer.lineWidth = _lineWidth + _extendLength; +- (CABasicAnimation *)animation{ - return layer; + CABasicAnimation * fillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; + fillAnimation.duration = [self countDuration:_index]; + fillAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; + fillAnimation.fillMode = kCAFillModeForwards; + fillAnimation.removedOnCompletion = NO; + fillAnimation.fromValue = @(0.f); + fillAnimation.toValue = @(1.f); + + return fillAnimation; } + + + #pragma mark - 清除控件 /** * 清除之前所有子控件 */ - (void)removeAllSubLayers{ - [self.startAngleArray removeAllObjects]; - [self.endAngleArray removeAllObjects]; + [self.angelArray removeAllObjects]; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, _originHeight); NSArray * subLayers = [NSArray arrayWithArray:self.layer.sublayers]; for (CALayer * layer in subLayers) { - if (layer != self.topicLabel.layer) { + if (layer != self.titleLabel.layer && layer != self.valueLabel.layer) { [layer removeAllAnimations]; [layer removeFromSuperlayer]; } } - NSArray * subviews = [NSArray arrayWithArray:self.subviews]; - for (UIView * view in subviews) { - if (view != self.topicLabel) { + for (UIView * view in self.subviews) { + if (view != self.titleLabel && view != self.valueLabel) { [view removeFromSuperview]; } } } -/** - * 移除半透明Path - */ -- (void)removeZFTranslucencePath{ - NSArray * sublayers = [NSArray arrayWithArray:self.layer.sublayers]; - for (CALayer * layer in sublayers) { - if ([layer isKindOfClass:[ZFTranslucencePath class]]) { - [layer removeFromSuperlayer]; - } - } -} - -#pragma mark - public method +#pragma mark - public method 重绘 /** * 重绘 */ - (void)strokePath{ - [self removeAllSubLayers]; - [self removeZFTranslucencePath]; - - if ([self.dataSource respondsToSelector:@selector(valueArrayInPieChart:)]) { - self.valueArray = [NSMutableArray arrayWithArray:[self.dataSource valueArrayInPieChart:self]]; - } - if ([self.dataSource respondsToSelector:@selector(nameArrayInPieChart:)]) { - self.nameArray = [NSMutableArray arrayWithArray:[self.dataSource nameArrayInPieChart:self]]; - } - - if ([self.dataSource respondsToSelector:@selector(colorArrayInPieChart:)]) { - self.colorArray = [NSMutableArray arrayWithArray:[self.dataSource colorArrayInPieChart:self]]; - } + self.userInteractionEnabled = NO; + [self removeAllSubLayers]; - //若为整圆样式,则改变半径大小 - if (_piePatternType == kPieChartPatternTypeForCircle) { - _radius = _maxRadius * ZFPieChartCircleRatio; - } + //开始绘制 + _startAngle = ZFRadian(-90); for (NSInteger i = 0; i < _valueArray.count; i++) { - NSDictionary * userInfo = @{@"index":@(i)}; - NSTimer * timer = [NSTimer timerWithTimeInterval:[self.startTimeArray[i] floatValue] target:self selector:@selector(timerAction:) userInfo:userInfo repeats:NO]; - [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; - } - - if (_nameArray) { - _isShowDetail ? [self addUI] : nil; + + [self dispatch_after_withSeconds:[self.startTimeArray[i] floatValue] actions:^{ + + _index = i; + + CAShapeLayer * shapeLayer = [self shapeLayer]; //调用getter 创建CAShapeLayer + + [self.layer addSublayer:shapeLayer]; + + _isShowPercent == YES?[self creatPercentLabel]:nil; + }]; } -} - -#pragma mark - 定时器 - -- (void)timerAction:(NSTimer *)sender{ - _index = [[sender.userInfo objectForKey:@"index"] integerValue]; - - //计算每个item所占角度大小 - CGFloat angle = [self countAngle:[_valueArray[_index] floatValue]]; - [self.layer addSublayer:[self pieShapeLayerWithCenter:_pieCenter startAngle:_startAngle endAngle:_startAngle + angle color:_colorArray[_index] duration:[self countDuration:_index] piePatternType:_piePatternType]]; - _centerPoint = [self getBezierPathCenterPointWithStartAngle:_startAngle endAngle:_startAngle + angle]; - [_startAngleArray addObject:@(_startAngle)]; - [_endAngleArray addObject:@(_startAngle + angle)]; - //临时记录下一个path的开始角度 - _startAngle += angle; + //绘制结束 - _isShowPercent ? [self creatPercentLabel] : nil; + [self dispatch_after_withSeconds:_totalDuration actions:^{ + self.userInteractionEnabled = YES; + }]; - [sender invalidate]; - sender = nil; + _isShowDetail == YES?[self addUI]:nil; } -#pragma mark - UIResponder -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ - [super touchesBegan:touches withEvent:event]; - UITouch * touch = [touches anyObject]; - CGPoint point = [touch locationInView:self]; - if (point.y > _pieCenter.y + _radius + 60) { - return; - } - - //求弧度 - CGFloat x = (point.x - _pieCenter.x); - CGFloat y = (point.y - _pieCenter.y); - CGFloat radian = atan2(y, x); - //当超过180度时,要加2π - if (y < 0 && x < 0) { - radian = radian + ZFRadian(360); - } - - //判断点击位置的角度在哪个path范围上 - for (NSInteger i = 0; i < _startAngleArray.count; i++) { - CGFloat startAngle = [_startAngleArray[i] floatValue]; - CGFloat endAngle = [_endAngleArray[i] floatValue]; - if (radian >= startAngle && radian < endAngle) { - [self removeZFTranslucencePath]; - [self.layer addSublayer:[self translucencePathShapeLayerWithStartAngle:startAngle endAngle:endAngle index:i]]; - UILabel * percentLabel = [self viewWithTag:PieChartPercentLabelTag + i]; - [self bringSubviewToFront:percentLabel]; - - return; - } - } -} -/** - * 显示半透明Path Action - * - * @param sender UITapGestureRecognizer - */ -- (void)showTranslucencePathAction:(UITapGestureRecognizer *)sender{ - NSInteger index = sender.view.tag - PieChartDetailBackgroundTag; - CGFloat startAngle = [_startAngleArray[index] floatValue]; - CGFloat endAngle = [_endAngleArray[index] floatValue]; - - [self removeZFTranslucencePath]; - [self.layer addSublayer:[self translucencePathShapeLayerWithStartAngle:startAngle endAngle:endAngle index:index]]; - UILabel * percentLabel = [self viewWithTag:PieChartPercentLabelTag + index]; - [self bringSubviewToFront:percentLabel]; -} -#pragma mark - 计算每个item所占角度大小 +#pragma mark - 获取每个item所占百分比 /** * 计算每个item所占角度大小 @@ -374,7 +319,7 @@ - (CGFloat)countAngle:(CGFloat)value{ return angle; } -#pragma mark - 计算每个部分执行动画持续时间 +#pragma mark - 计算每个圆弧执行动画持续时间 /** * 计算每个圆弧执行动画持续时间 @@ -394,6 +339,7 @@ - (CFTimeInterval)countDuration:(NSInteger)index{ return time; } + #pragma mark - 获取每个path的中心点 /** @@ -415,21 +361,22 @@ - (CGPoint)getBezierPathCenterPointWithStartAngle:(CGFloat)startAngle endAngle:( return CGPointMake(center_xPos, center_yPos); } -#pragma mark - 添加百分比Label +#pragma mark - 添加百分比Label /** * 添加百分比Label */ - (void)creatPercentLabel{ NSString * string = [self getPercent:_index]; - CGRect rect = [string stringWidthRectWithSize:CGSizeMake(0, 0) fontOfSize:_percentOnChartFontSize isBold:YES]; + CGRect rect = CGRectMake(0, 0, 0, 0); + UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, rect.size.height)]; label.text = string; label.alpha = 0.f; label.textAlignment = NSTextAlignmentCenter; - label.font = [UIFont boldSystemFontOfSize:_percentOnChartFontSize]; - label.center = _centerPoint; - label.tag = PieChartPercentLabelTag + _index; + label.font = [UIFont boldSystemFontOfSize:9.f]; + label.center = self.centerPoint; + label.tag = PercentLabelTag + _index; [self addSubview:label]; [UIView animateWithDuration:[self countDuration:_index] animations:^{ @@ -451,6 +398,7 @@ - (void)creatPercentLabel{ * @return NSString */ - (NSString *)getPercent:(NSInteger)index{ + CGFloat percent = [_valueArray[index] floatValue] / _totalValue * 100; NSString * string; if (self.percentType == kPercentTypeDecimal) { @@ -464,11 +412,13 @@ - (NSString *)getPercent:(NSInteger)index{ #pragma mark - 重写setter,getter方法 - (void)setValueArray:(NSMutableArray *)valueArray{ + _valueArray = valueArray; _totalValue = 0; + [self.startTimeArray removeAllObjects]; - CFTimeInterval startTime = 0.f; + CFTimeInterval startTime = 0.f; //计算总数 for (NSInteger i = 0; i < valueArray.count; i++) { _totalValue += [valueArray[i] floatValue]; @@ -482,9 +432,120 @@ - (void)setValueArray:(NSMutableArray *)valueArray{ } } -- (void)setTopic:(NSString *)topic{ - _topic = topic; - self.topicLabel.text = _topic; + + +- (void)setTitle:(NSString *)title{ + _title = title; + self.titleLabel.text = _title; +} + + + + + + + + + + + + + +#pragma mark - UIResponder + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + + //mxt518 手势暂时屏蔽 + return; + + [super touchesBegan:touches withEvent:event]; + UITouch * touch = [touches anyObject]; + CGPoint point = [touch locationInView:self]; + if (point.y > _originHeight / 8.f * 7 + 30) { + return; + } + + //求弧度 + CGFloat x = (point.x - _pieCenter.x); + CGFloat y = (point.y - _pieCenter.y); + CGFloat radian = atan2(y, x); + //当超过180度时,要加2π + if (y < 0 && x < 0) { + radian = radian + ZFRadian(360); + } + + //判断点击位置的角度在哪个path范围上 + for (NSInteger i = 0; i < self.angelArray.count; i++) { + NSDictionary * dict = self.angelArray[i]; + CGFloat startAngle = [dict[@"startAngle"] floatValue]; + CGFloat endAngle = [dict[@"endAngle"] floatValue]; + + if (radian >= startAngle && radian < endAngle) { + [self removeZFTranslucencePath]; + [self.layer addSublayer:[self translucencePathShapeLayerWithStartAngle:startAngle endAngle:endAngle index:i]]; + UILabel * percentLabel = [self viewWithTag:PercentLabelTag + i]; + [self bringSubviewToFront:percentLabel]; + // self.valueLabel.text = _valueArray[i]; + + return; + } + } +} + +/** + * 显示半透明Path Action + * + * @param sender UITapGestureRecognizer + */ +- (void)showTranslucencePathAction:(UITapGestureRecognizer *)sender{ + + //mxt518 手势暂时屏蔽 + return; + + NSInteger index = sender.view.tag - DetailBackgroundTag; + NSDictionary * dict = self.angelArray[index]; + CGFloat startAngle = [dict[@"startAngle"] floatValue]; + CGFloat endAngle = [dict[@"endAngle"] floatValue]; + + [self removeZFTranslucencePath]; + [self.layer addSublayer:[self translucencePathShapeLayerWithStartAngle:startAngle endAngle:endAngle index:index]]; + UILabel * percentLabel = [self viewWithTag:PercentLabelTag + index]; + [self bringSubviewToFront:percentLabel]; + self.valueLabel.text = _valueArray[index]; +} + + +# pragma mark - - 移除半透明Path +- (void)removeZFTranslucencePath{ + NSMutableArray * sublayers = [NSMutableArray arrayWithArray:self.layer.sublayers]; + for (CALayer * layer in sublayers) { + + if ([layer isKindOfClass:[ZFTranslucencePath class]]) { + [layer removeFromSuperlayer]; + } + } +} + + +#pragma mark - 半透明Path +/** + * 半透明Path + * + * @param startAngle 开始角度 + * @param endAngle 结束角度 + * @param index 下标 + * + * @return ZFTranslucencePath + */ +- (ZFTranslucencePath *)translucencePathShapeLayerWithStartAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle index:(NSInteger)index{ + ZFTranslucencePath * layer = [ZFTranslucencePath layerWithArcCenter:_pieCenter radius:_radius + _extendLength startAngle:startAngle endAngle:endAngle clockwise:YES]; + layer.strokeColor = [_colorArray[index] CGColor]; + layer.lineWidth = _lineWidth + _extendLength; + return layer; } + + + + @end From 9b25cf02420298be0f600abd2f737ae6cfbe47a5 Mon Sep 17 00:00:00 2001 From: xinruan Date: Mon, 23 May 2016 16:55:12 -0700 Subject: [PATCH 8/8] 2 --- ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m index f3f86a0..b127412 100644 --- a/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m +++ b/ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m @@ -67,7 +67,7 @@ - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { [self commonInit]; - [self drawGenericChart]; + [self drawGenericChart];//画坐标轴 //标题Label self.topicLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width/4 ,0, self.frame.size.width/2, 30)];