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
Binary file modified ZFChartView/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (void)viewDidLoad{
self.pieChart = [[ZFPieChart alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, _height)];
self.pieChart.dataSource = self;
self.pieChart.delegate = self;
// self.pieChart.piePatternType = kPieChartPatternTypeForCircle;
self.pieChart.piePatternType = kPieChartPatternTypeCircle;
// self.pieChart.percentType = kPercentTypeInteger;
// self.pieChart.isShadow = NO;
// self.pieChart.isAnimated = NO;
Expand All @@ -47,6 +47,9 @@ - (void)viewDidLoad{
}

#pragma mark - ZFPieChartDataSource
- (NSArray <NSString *> *)titleArrayInPieChart:(ZFPieChart *)pieChart{
return @[@"apple", @"suns", @"Mi", @"meizu", @"oppo", @"vivo"];
}

- (NSArray *)valueArrayInPieChart:(ZFPieChart *)chart{
return @[@"50", @"256", @"300", @"283", @"490", @"236"];
Expand Down
8 changes: 8 additions & 0 deletions ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
*/
- (NSArray *)colorArrayInPieChart:(ZFPieChart *)pieChart;

/**
* value标题
*
* @return NSArray必须存储NSString类型
*/

- (NSArray <NSString *> *)titleArrayInPieChart:(ZFPieChart *)pieChart;

@end


Expand Down
11 changes: 10 additions & 1 deletion ZFChartView/ZFChartView/ZFChart/ZFPieChart/ZFPieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

@interface ZFPieChart()

/** 存储title的数组 */
@property (nonatomic, strong) NSMutableArray <NSString *>* titleArray;
/** 存储value的数组 */
@property (nonatomic, strong) NSMutableArray * valueArray;
/** 存储颜色的数组 */
Expand Down Expand Up @@ -171,7 +173,9 @@ - (void)removeZFTranslucencePath{
- (void)strokePath{
[self removeAllSubLayers];
[self removeZFTranslucencePath];

if ([self.dataSource respondsToSelector:@selector(titleArrayInPieChart:)]) {
self.titleArray = [NSMutableArray arrayWithArray:[self.dataSource titleArrayInPieChart:self]];
}
if ([self.dataSource respondsToSelector:@selector(valueArrayInPieChart:)]) {
self.valueArray = [NSMutableArray arrayWithArray:[self.dataSource valueArrayInPieChart:self]];

Expand Down Expand Up @@ -354,8 +358,13 @@ - (CGPoint)getBezierPathCenterPointWithStartAngle:(CGFloat)startAngle endAngle:(
*/
- (void)creatPercentLabel:(NSInteger)i{
NSString * string = [self getPercent:i];
if (i < self.titleArray.count) {
NSString * title = self.titleArray[i];
string = [NSString stringWithFormat:@"%@\n%@", string ,title];
}
CGRect rect = [string stringWidthRectWithSize:CGSizeMake(0, 0) font:_percentOnChartFont];
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, rect.size.height)];
label.numberOfLines = 0;
label.text = string;
label.alpha = 0.f;
label.textAlignment = NSTextAlignmentCenter;
Expand Down