PNChart,简洁高效有动画效果的iOS图表库

示意图

导入

项目中引用头文件#import"PNChart.h"

折线图

PNLineChart * lineChart = [[PNLineChartalloc]initWithFrame:CGRectMake(0,135.0,SCREEN_WIDTH,200.0)];
//X轴数据
[lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]];
    
//Y轴数据
NSArray * data01Array =@[@60.1,@160.1,@126.4,@262.2,@186.2];
PNLineChartData *data01 = [PNLineChartDatanew];
data01.color = PNFreshGreen;
data01.itemCount = lineChart.xLabels.count;
data01.getData = ^(NSUInteger index) {
    CGFloat yValue = [data01Array[index] floatValue];
    return [PNLineChartDataItemdataItemWithY:yValue];
};
    
//可以添加多条折线
NSArray * data02Array =@[@20.1,@180.1,@26.4,@202.2,@126.2];
PNLineChartData *data02 = [PNLineChartDatanew];
data02.color = PNTwitterColor;
data02.itemCount = lineChart.xLabels.count;
data02.getData = ^(NSUInteger index) {
    CGFloat yValue = [data02Array[index] floatValue];
    return [PNLineChartDataItemdataItemWithY:yValue];
};
    
lineChart.chartData = @[data01, data02];
[lineChart strokeChart];
//加载在视图上
[self.windowaddSubview:lineChart];

柱状图

PNBarChart * barChart = [[PNBarChartalloc]initWithFrame:CGRectMake(0,135.0,SCREEN_WIDTH,200.0)];
 //X轴数据
[barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]];
//Y轴数据
[barChart setYValues:@[@1, @10,@2,@6,@3]];
[barChart strokeChart];
    
//加载在视图上
[self.windowaddSubview:barChart];

饼状图

PNPieChart *pieChart = [[PNPieChartalloc]initWithFrame:CGRectMake(40.0,155.0,240.0,240.0)items:items];
//饼状图文字颜色
pieChart.descriptionTextColor = [UIColorwhiteColor];
pieChart.descriptionTextFont  = [UIFontfontWithName:@"Avenir-Medium"size:14.0];
//绘制
[pieChart strokeChart];
    
//加载在视图上
[self.windowaddSubview:pieChart];

圆形进度条

// total参数是进度条的总数据量,current是当前的数据量,closewise是绘制方向,YES是从左到右,NO为从右到左
PNCircleChart *circleChart = [[PNCircleChartalloc]initWithFrame:CGRectMake(40.0,155.0,240.0,240.0)total:@100current:@30clockwise:NO];
    
//绘制图形
[circleChart strokeChart];
    
//加载在视图上
[self.windowaddSubview:circleChart];

注: 文章由我们 iOS122(http://www.ios122.com)的小伙伴 @偌一茗 整理,喜欢就一起参与: iOS122 任务池

posted @ 2015-11-06 00:17  iOS122  阅读(2793)  评论(0编辑  收藏  举报