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 任務池github

相關文章
相關標籤/搜索