图片 1

导入

类型中引用头文件#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)的同伙%E7%9A%84%E5%B0%8F%E4%BC%99%E4%BC%B4)
@偌一茗 整理,喜欢就一起插足: iOS122
任务池

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图