pod導入相對簡單,要手動導入這個庫,先下載下來(https://github.com/kevinzhow/PNChart),解壓後把PNChart文件夾拖入工程中ios
運行發現#import"PNRadarChartDataItem.h"報紅,在它的.h文件裏引入#import<UIKit/UIKit.h>頭文件;#import<UICountingLabel/UICountingLabel.h>報錯,下載UICountingLabel(https://github.com/dataxpress/UICountingLabel)解壓後把UICountingLabel的.m和.h文件拖入工程,把報錯的#import<UICountingLabel/UICountingLabel.h>頭文件換爲#import"UICountingLabel.h"git
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