#define MAIN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define MAIN_HEIGHT [[UIScreen mainScreen] bounds].size.height
//1.PNCircleChart圓環=================================
//初始化圓環PNCircleChart最后一個初始化方法功能比較齊全
//total總圓100單位
//current占總圓的80單位
//clockwise順時針方向YES
//shadow有陰影YES
//shadowColor陰影顏色greenColor
//displayCountingLabel是否顯示計數標簽YES
//overrideLineWidth圓環的寬20像素
PNCircleChart * circleChart = [[PNCircleChart alloc]initWithFrame:CGRectMake(0, 150, MAIN_WIDTH, 200) total:[NSNumber numberWithInt:100] current:[NSNumber numberWithInt:80] clockwise:YES shadow:YES shadowColor:[UIColor greenColor] displayCountingLabel:YES overrideLineWidth:[NSNumber numberWithInt:20]];
//設置顏色
[circleChart setStrokeColorGradientStart:[UIColor redColor]];
//開始畫圓
[circleChart strokeChart];
//背景顏色
circleChart.backgroundColor = [UIColor yellowColor];
//Add
[self.view addSubview:circleChart];
//效果如下圖
//2.PNLineChart折線圖=================================
PNLineChart *lineChart = [[PNLineChart alloc]initWithFrame:CGRectMake(0, 150, MAIN_WIDTH, 300)];
//設置背景顏色
lineChart.backgroundColor = [UIColor yellowColor];
//設置坐標軸是否可見
lineChart.showCoordinateAxis = YES;
//設置是否顯示網格線
lineChart.showYGridLines = YES;
//設置網格線顏色
lineChart.yGridLinesColor = [UIColor grayColor];
//設置X軸標簽
lineChart.xLabels = @[@"魅族",@"華為",@"中興",@"小米",@"蘋果",@"一加",@"樂視"];
//設置坐標軸顏色
lineChart.axisColor = [UIColor blueColor];
//設置坐標軸寬度
lineChart.axisWidth = 2.0;
//Add
[self.view addSubview:lineChart];
//曲線數據1
PNLineChartData *data1 = [[PNLineChartData alloc]init];
//曲線顏色
data1.color = PNRed;
//曲線格式
data1.inflexionPointStyle = PNLineChartPointStyleCircle;
//設置數據(Y軸坐標根據數據的大小自動適應)
NSArray *dataArray1 = @[@4,@8,@7,@4,@19,@6,@5];
data1.itemCount = dataArray1.count;
data1.getData = ^(NSUInteger index){
CGFloat yValue = [dataArray1[index] floatValue];
return [ PNLineChartDataItem dataItemWithY:yValue];
};
//曲線數據2
PNLineChartData *data2 = [[PNLineChartData alloc]init];
//曲線顏色
data2.color = PNGreen;
//曲線格式
data2.inflexionPointStyle = PNLineChartPointStyleCircle;
//設置數據(Y軸坐標根據數據的大小自動適應)
NSArray *dataArray2 = @[@6,@15,@3,@12,@20,@16,@3];
data2.itemCount = dataArray2.count;
data2.getData = ^(NSUInteger index){
CGFloat yValue = [dataArray2[index] floatValue];
return [ PNLineChartDataItem dataItemWithY:yValue];
};
lineChart.chartData = @[data1,data2];
//開始繪圖
[lineChart strokeChart];
//數據標注名稱
data1.dataTitle = @"數據1標注名稱";
data2.dataTitle = @"數據2標注名稱";
//標注擺放樣式
lineChart.legendStyle = PNLegendItemStyleSerial;
//標注字體
lineChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
//標注顏色
lineChart.legendFontColor = [UIColor redColor];
// 標示所在的View
UIView *legend = [lineChart getLegendWithMaxWidth:MAIN_WIDTH];
[legend setFrame:CGRectMake(0, 480, legend.frame.size.width, legend.frame.size.height)];
legend.backgroundColor = [UIColor yellowColor];
[self.view addSubview:legend];
//效果圖如下
//3.PNBarChart柱狀圖=================================
PNBarChart *barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 150, MAIN_WIDTH, 300)];
barChart.backgroundColor = [UIColor yellowColor];
//Y坐標label寬度(微調)
barChart.yChartLabelWidth = 20.0;
barChart.chartMarginLeft = 30.0;
barChart.chartMarginRight = 10.0;
barChart.chartMarginTop = 5.0;
barChart.chartMarginBottom = 10.0;
//X坐標刻度的上邊距
barChart.labelMarginTop = 2.0;
//是否顯示坐標軸
barChart.showChartBorder = YES;
[barChart setXLabels:@[@"魅族",@"華為",@"中興",@"小米",@"蘋果",@"樂視"]];
[barChart setYValues:@[@20,@8,@5,@33,@16,@8]];
//每個柱子的顏色
[barChart setStrokeColors:@[PNGreen,PNRed,PNRed,PNRed,PNRed,PNRed]];
//? ? barChart.strokeColor = [UIColor redColor];
//是否立體效果
barChart.isGradientShow = NO;
//顯示各條狀圖的數值
barChart.isShowNumbers = YES;
//開始繪圖
[barChart strokeChart];
barChart.delegate = self;
//Add
[self.view addSubview:barChart];
//效果圖如下
//4.PNPieChart圓餅圖=================================
//圓餅數據
NSArray *items = @[[PNPieChartDataItem dataItemWithValue:30 color:PNRed],
[PNPieChartDataItem dataItemWithValue:10 color:PNFreshGreen description:@"綠色"],
[PNPieChartDataItem dataItemWithValue:60 color:PNBlue description:@"藍色"],
];
//PNPieChart初始化
PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH /2 - 100, 150, 200, 200) items:items];
pieChart.backgroundColor = [UIColor yellowColor];
//扇形上字體顏色
pieChart.descriptionTextColor = [UIColor whiteColor];
pieChart.descriptionTextFont? = [UIFont fontWithName:@"Avenir-Medium" size:11.0];
// 陰影顏色
pieChart.descriptionTextShadowColor = [UIColor yellowColor];
//顯示實際數值(不顯示比例數字)
pieChart.showAbsoluteValues = YES;
// 只顯示數值不顯示內容描述
pieChart.showOnlyValues = NO;
//開始繪圖
[pieChart strokeChart];
//Add
[self.view addSubview:pieChart];
// 標注排放樣式
pieChart.legendStyle = PNLegendItemStyleStacked;
pieChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
UIView *legend = [pieChart getLegendWithMaxWidth:200];
[legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)];
[self.view addSubview:legend];
//效果圖如下
//5.PNRadarChart無線電圖=================================
//View背景顏色
self.view.backgroundColor = [UIColor yellowColor];
NSArray *items = @[[PNRadarChartDataItem dataItemWithValue:6 description:@"語文"],
[PNRadarChartDataItem dataItemWithValue:20 description:@"數學"],
[PNRadarChartDataItem dataItemWithValue:8 description:@"英語"],
[PNRadarChartDataItem dataItemWithValue:5 description:@"體育"],
[PNRadarChartDataItem dataItemWithValue:9 description:@"美術"],
[PNRadarChartDataItem dataItemWithValue:4 description:@"其他的"]
];
PNRadarChart *radarChart = [[PNRadarChart alloc] initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, 300.0) items:items valueDivider:2];
//開始繪圖
[radarChart strokeChart];
//Add
[self.view addSubview:radarChart];
//效果圖如下
//