Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ZFChartView/ZFChartView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand All @@ -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)";
Expand Down
10 changes: 7 additions & 3 deletions ZFChartView/ZFChartView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="qv0-76-ln7">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="qv0-76-ln7">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<scenes>
<!--Root View Controller-->
Expand All @@ -12,15 +12,18 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="QeA-yM-lJq">
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="HH0-oe-k3P">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="HH0-oe-k3P" id="pJR-dU-W0p">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</tableViewCellContentView>
<animations/>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -42,6 +45,7 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="qqW-Qj-s7D">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<connections>
<segue destination="y7R-ca-ZXP" kind="relationship" relationship="rootViewController" id="1hM-Yl-3iA"/>
Expand Down
46 changes: 26 additions & 20 deletions ZFChartView/ZFChartView/ViewController/PieChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
//

#import "PieChartViewController.h"

#import "ZFChart.h"

@interface PieChartViewController()<ZFPieChartDataSource>
@interface PieChartViewController()
{
ZFPieChart *pieChart;
}

@end

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,45 @@ @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 = @"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.isShowSeparate = YES;
// barChart.backgroundColor = ZFGreen;
barChart.valueLabelPattern = kPopoverLabelPatternPopover;
//isShadowForValueLabel
barChart.isShadowForValueLabel = NO;
// barChart.overMaxValueBarColor = [UIColor orangeColor];
[self.view addSubview:barChart];


[barChart strokePath];
}

#pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
return @[@"123", @"256", @"300", @"283", @"490", @"236"];
return @[@"2.01", @"3.02", @"4.03", @"5.11", @"6.50", @"7.7"];
}

- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"];
return @[@"7天", @"3个月", @"6个月", @"一年", @"二年", @"三年"];
}

- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
return @[ZFSkyBlue];
}

- (CGFloat)yLineMaxValueInGenericChart:(ZFGenericChart *)chart{
return 500;
return 8;
}

- (NSInteger)yLineSectionCountInGenericChart:(ZFGenericChart *)chart{
return 10;
return 4;
}

#pragma mark - ZFBarChartDelegate
Expand All @@ -70,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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ - (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];
}

#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{
Expand Down
2 changes: 2 additions & 0 deletions ZFChartView/ZFChartView/ZFChart/Other/ZFColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/**
* 直接填写小数
*/
Expand Down
13 changes: 9 additions & 4 deletions ZFChartView/ZFChartView/ZFChart/ZFBarChart/ZFBarChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ - (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
[self drawGenericChart];
[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];
}
Expand Down Expand Up @@ -103,13 +104,15 @@ - (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轴显示上限时,柱状改为红色
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;
Expand Down Expand Up @@ -207,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];
}
Expand Down
24 changes: 16 additions & 8 deletions ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFGenericAxis.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -92,29 +94,31 @@ - (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 = [[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];
}

#pragma mark - 设置x轴标题Label

/**
* 设置x轴标题Label
* 设置x轴标题Label x
*/
- (void)setXLineNameLabel{
if (self.xLineNameArray.count > 0) {
for (NSInteger i = 0; i < self.xLineNameArray.count; i++) {
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);
Expand All @@ -124,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];
}
}
Expand Down Expand Up @@ -209,7 +214,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;

Expand Down
6 changes: 4 additions & 2 deletions ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFXAxisLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down Expand Up @@ -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]];
Expand Down
11 changes: 8 additions & 3 deletions ZFChartView/ZFChartView/ZFChart/ZFGenericAxis/ZFYAxisLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
Loading