-
OC 使用 pod集成 Charts庫時 要在podefie中 加上 use_frameworks! ! 如圖
a.png
2.在OC項目創(chuàng)建 swift的文件并生成橋接文件





3.如果集成報錯做如下操作

到這里就將Charts 集成到及的項目中啦
實例1.折線的創(chuàng)建
-(void)zxinit
{
self.lineView=[[LineChartView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
[self.view addSubview:self.lineView];
self.lineView.delegate=self;
//設(shè)置折線圖描述
self.lineView.noDataText=@"戰(zhàn)無數(shù)據(jù)"; //沒數(shù)據(jù)時顯示
//self.lineView.drawBordersEnabled=YES; //
// self.lineView.drawGridBackgroundEnabled=NO;
self.lineView.scaleYEnabled=NO; //啟動Y軸縮放
self.lineView.scaleXEnabled=NO; //啟動X軸縮放
self.lineView.doubleTapToZoomEnabled=NO; //取消雙擊縮放
self.lineView.dragEnabled=YES; //啟動拖拽圖標
self.lineView.dragDecelerationEnabled=YES; //拖拽后是否有慣性效果
self.lineView.dragDecelerationFrictionCoef = 0.9;//拖拽后慣性效果的摩擦系數(shù)(0~1),數(shù)值越小,慣性越不明顯
//設(shè)置X軸樣式
ChartXAxis *xAxis = self.lineView.xAxis;
xAxis.axisLineWidth = 1.0/[UIScreen mainScreen].scale;//設(shè)置X軸線寬
xAxis.labelCount=11;
xAxis.labelPosition = XAxisLabelPositionBottom;//X軸的顯示位置,默認是顯示在上面的
xAxis.drawGridLinesEnabled = NO;//不繪制網(wǎng)格線
// xAxis.spaceBetweenLabels = 4;//設(shè)置label間隔
xAxis.labelTextColor = [UIColor orangeColor];//label文字顏色
//設(shè)置Y軸樣式
self.lineView.rightAxis.enabled = NO;//不繪制右邊軸
ChartYAxis *leftAxis = self.lineView.leftAxis;//獲取左邊Y軸
leftAxis.labelCount = 11;//Y軸label數(shù)量,數(shù)值不一定,如果forceLabelsEnabled等于YES, 則強制繪制制定數(shù)量的label, 但是可能不平均
leftAxis.forceLabelsEnabled = NO;//不強制繪制指定數(shù)量的label
// leftAxis.showOnlyMinMaxEnabled = NO;//是否只顯示最大值和最小值
leftAxis.axisMinimum = 0;//設(shè)置Y軸的最小值
leftAxis.drawZeroLineEnabled = YES;//從0開始繪制
leftAxis.axisMaximum = 105;//設(shè)置Y軸的最大值
leftAxis.inverted = NO;//是否將Y軸進行上下翻轉(zhuǎn)
leftAxis.axisLineWidth = 1.0/[UIScreen mainScreen].scale;//Y軸線寬
leftAxis.axisLineColor = [UIColor blackColor];//Y軸顏色
// leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];//自定義格式
// leftAxis.valueFormatter.positiveSuffix = @" $";//數(shù)字后綴單位
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
leftAxis.labelTextColor =[UIColor orangeColor];//文字顏色
leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字體
//設(shè)置網(wǎng)格樣式
leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//設(shè)置虛線樣式的網(wǎng)格線
leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//網(wǎng)格線顏色
leftAxis.gridAntialiasEnabled = YES;//開啟抗鋸齒
//設(shè)置限制線
ChartLimitLine *limitLine = [[ChartLimitLine alloc] initWithLimit:100 label:@"限制線"];
limitLine.lineWidth = 2;
limitLine.lineColor = [UIColor greenColor];
limitLine.lineDashLengths = @[@5.0f, @5.0f];//虛線樣式
limitLine.labelPosition = ChartLimitLabelPositionLeftBottom;//位置
limitLine.valueTextColor =[UIColor blueColor];//label文字顏色
limitLine.valueFont = [UIFont systemFontOfSize:12];//label字體
[leftAxis addLimitLine:limitLine];//添加到Y(jié)軸上
leftAxis.drawLimitLinesBehindDataEnabled = YES;//設(shè)置限制線繪制在折線圖的后面
//設(shè)置折線圖描述及圖例樣式
//[self.lineView setDescriptionText:@"折線圖"];//折線圖描述
// [self.lineView setDescriptionTextColor:[UIColor darkGrayColor]];
// self.lineView.legend.form = ChartLegendFormLine;//圖例的樣式
// self.lineView.legend.formSize = 30;//圖例中線條的長度
// self.lineView.legend.textColor = [UIColor darkGrayColor];//圖例文字顏色
//汽包
BalloonMarker *markerA=[[BalloonMarker alloc]initWithColor:[UIColor orangeColor] font:[UIFont systemFontOfSize:12] textColor:[UIColor whiteColor] insets:UIEdgeInsetsMake(9.0, 8.0, 20.0, 8.0)];
markerA.chartView=self.lineView;
markerA.minimumSize=CGSizeMake(50.f, 25.f);
self.lineView.marker=markerA;
self.lineView.data=[self zxData];
}
-(LineChartData *)zxData
{
int xVals_count = 12;//X軸上要顯示多少條數(shù)據(jù)
double maxYVal = 100;//Y軸的最大值
//X軸上面需要顯示的數(shù)據(jù)
NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < xVals_count; i++) {
[xVals addObject:[NSString stringWithFormat:@"%d", i+1]];
}
//對應(yīng)Y軸上面需要顯示的數(shù)據(jù)
NSMutableArray *yVals = [[NSMutableArray alloc] init];
for (int i = 0; i < xVals_count; i++) {
double mult = maxYVal + 1;
double val = (double)(arc4random_uniform(mult));
ChartDataEntry *entry =[[ChartDataEntry alloc]initWithX:i y:val]; //[[ChartDataEntry alloc] initWithValue:val xIndex:i];
[yVals addObject:entry];
}
LineChartDataSet *set1 = nil;
if (self.lineView.data.dataSetCount > 0) {
LineChartData *data = (LineChartData *)self.lineView.data;
set1 = (LineChartDataSet *)data.dataSets[0];
//set1.=yVals;
return data;
}else{
//創(chuàng)建LineChartDataSet對象
set1=[[LineChartDataSet alloc]initWithValues:yVals label:@"A"];
//設(shè)置折線的樣式
set1.lineWidth = 1.0/[UIScreen mainScreen].scale;//折線寬度
set1.drawValuesEnabled = YES;//是否在拐點處顯示數(shù)據(jù)
set1.valueColors = @[[UIColor brownColor]];//折線拐點處顯示數(shù)據(jù)的顏色
[set1 setColor:[UIColor greenColor]];//折線顏色
//set1.drawSteppedEnabled = NO;//是否開啟繪制階梯樣式的折線圖
//折線拐點樣式
set1.drawCirclesEnabled = NO;//是否繪制拐點
set1.circleRadius = 4.0f;//拐點半徑
set1.circleColors = @[[UIColor redColor], [UIColor greenColor]];//拐點顏色
//拐點中間的空心樣式
set1.drawCircleHoleEnabled = YES;//是否繪制中間的空心
set1.circleHoleRadius = 2.0f;//空心的半徑
set1.circleHoleColor = [UIColor blackColor];//空心的顏色
//折線的顏色填充樣式
//第一種填充樣式:單色填充
// set1.drawFilledEnabled = YES;//是否填充顏色
// set1.fillColor = [UIColor redColor];//填充顏色
// set1.fillAlpha = 0.3;//填充顏色的透明度
//第二種填充樣式:漸變填充
set1.drawFilledEnabled = YES;//是否填充顏色
NSArray *gradientColors = @[(id)[ChartColorTemplates colorFromString:@"#FFFFFFFF"].CGColor,
(id)[ChartColorTemplates colorFromString:@"#FF007FFF"].CGColor];
CGGradientRef gradientRef = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);
set1.fillAlpha = 0.3f;//透明度
set1.fill = [ChartFill fillWithLinearGradient:gradientRef angle:90.0f];//賦值填充顏色對象
CGGradientRelease(gradientRef);//釋放gradientRef
//點擊選中拐點的交互樣式
set1.highlightEnabled = YES;//選中拐點,是否開啟高亮效果(顯示十字線)
set1.highlightColor = [UIColor darkGrayColor];//點擊選中拐點的十字線的顏色
set1.highlightLineWidth = 1.0/[UIScreen mainScreen].scale;//十字線寬度
set1.highlightLineDashLengths = @[@5, @5];//十字線的虛線樣式
//將 LineChartDataSet 對象放入數(shù)組中
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
//添加第二個LineChartDataSet對象
LineChartDataSet *set2 = [set1 copy];
NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
for (int i = 0; i < xVals_count; i++) {
double mult = maxYVal + 1;
double val = (double)(arc4random_uniform(mult));
ChartDataEntry *entry =[[ChartDataEntry alloc]initWithX:i y:val]; //[[ChartDataEntry alloc] initWithValue:val xIndex:i];
[yVals2 addObject:entry];
}
// set2.yVals = yVals2;
set2.values=yVals2;
set2.label=@"B";
[set2 setColor:[UIColor redColor]];
set2.drawFilledEnabled = YES;//是否填充顏色
set2.fillColor = [UIColor redColor];//填充顏色
set2.fillAlpha = 0.1;//填充顏色的透明度
[dataSets addObject:set2];
//創(chuàng)建 LineChartData 對象, 此對象就是lineChartView需要最終數(shù)據(jù)對象
LineChartData *data=[[LineChartData alloc]initWithDataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:8.f]];//文字字體
[data setValueTextColor:[UIColor grayColor]];//文字顏色
// NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
//自定義數(shù)據(jù)顯示格式
// [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
// [formatter setPositiveFormat:@"#0.0"];
// [data setValueFormatter:formatter];
return data;
}
//效果如圖

實例2.條形圖
-(void)txinit
{
self.chartView=[[BarChartView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
self.chartView.delegate=self;
[self.view addSubview:self.chartView];
self.chartView.noDataText=@"戰(zhàn)無數(shù)據(jù)"; //沒數(shù)據(jù)時顯示
self.chartView.drawValueAboveBarEnabled=YES; //數(shù)值顯示在柱形的上面還是下面
self.chartView.drawBarShadowEnabled=NO; //是否繪制柱形的陰影背景
self.chartView.scaleYEnabled=NO; //啟動Y軸縮放
self.chartView.scaleXEnabled=NO; //啟動X軸縮放
self.chartView.doubleTapToZoomEnabled=NO; //取消雙擊縮放
self.chartView.dragEnabled=YES; //啟動拖拽圖標
self.chartView.dragDecelerationEnabled=YES; //拖拽后是否有慣性效果
self.chartView.dragDecelerationFrictionCoef = 0.9;//拖拽后慣性效果的摩擦系數(shù)(0~1),數(shù)值越小,慣性越不明顯
//設(shè)置X軸的樣式
ChartXAxis *xAxis=self.chartView.xAxis;
xAxis.axisLineWidth=1; //X軸的線寬
xAxis.labelPosition = XAxisLabelPositionBottom;//X軸的顯示位置,默認是顯示在上面的
xAxis.drawGridLinesEnabled = NO;//不繪制網(wǎng)格線
xAxis.labelCount=12; //label的個數(shù)
//xAxis. = 4;//設(shè)置label間隔,若設(shè)置為1,則如果能全部顯示,則每個柱形下面都會顯示label
//xAxis.spaceMin=0;
// xAxis.spaceMax=1;
xAxis.labelTextColor = [UIColor brownColor];//label文字顏色
//設(shè)置Y軸的樣式
self.chartView.rightAxis.enabled=NO; //不繪制右邊軸
ChartYAxis *leftAxis=self.chartView.leftAxis;
leftAxis.forceLabelsEnabled = NO;//不強制繪制制定數(shù)量的label
leftAxis.axisMinimum = 0;//設(shè)置Y軸的最小值
leftAxis.drawZeroLineEnabled = YES;//從0開始繪制
leftAxis.axisMaximum = 105;//設(shè)置Y軸的最大值
leftAxis.inverted = NO;//是否將Y軸進行上下翻轉(zhuǎn)
leftAxis.axisLineWidth = 0.5;//Y軸線寬
// leftAxis.axisMinLabels=1; //軸上標簽的最小數(shù)目
//leftAxis.axisMaxLabels=100;//軸上標簽的最大數(shù)目
leftAxis.axisLineColor = [UIColor blackColor];//Y軸顏色
leftAxis.labelCount = 5; //通過labelCount屬性設(shè)置Y軸要均分的數(shù)量.設(shè)置的labelCount的值不一定就是Y軸要均分的數(shù)量,這還要取決于forceLabelsEnabled屬性,
leftAxis.forceLabelsEnabled = NO; //如果forceLabelsEnabled等于YES, 則強制繪制指定數(shù)量的label, 但是可能不是均分的
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
leftAxis.labelTextColor = [UIColor brownColor];//文字顏色
leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字體
// 設(shè)置Y軸上標簽顯示數(shù)字的格式,代碼如下:
//leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];//自定義格式
//leftAxis.valueFormatter.pos = @" $";//數(shù)字后綴單位
// 設(shè)置Y軸上網(wǎng)格線的樣式,代碼如下:
leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//設(shè)置虛線樣式的網(wǎng)格線
leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//網(wǎng)格線顏色
leftAxis.gridAntialiasEnabled = YES;//開啟抗鋸齒
//設(shè)置限制線
ChartLimitLine *limitLine = [[ChartLimitLine alloc] initWithLimit:80 label:@"限制線"];
limitLine.lineWidth = 2;
limitLine.lineColor = [UIColor greenColor];
limitLine.lineDashLengths = @[@5.0f, @5.0f];//虛線樣式
limitLine.labelPosition = ChartLimitLabelPositionRightTop;//位置
[leftAxis addLimitLine:limitLine];//添加到Y(jié)軸上
leftAxis.drawLimitLinesBehindDataEnabled = YES;//設(shè)置限制線繪制在柱形圖的后面
self.chartView.legend.enabled=NO; //不顯示圖利說明
// self.chartView.=@"";
//汽包
BalloonMarker *markerA=[[BalloonMarker alloc]initWithColor:[UIColor orangeColor] font:[UIFont systemFontOfSize:12] textColor:[UIColor whiteColor] insets:UIEdgeInsetsMake(9.0, 8.0, 20.0, 8.0)];
markerA.chartView=self.chartView;
markerA.minimumSize=CGSizeMake(50.f, 25.f);
self.chartView.marker=markerA;
self.chartView.data=[self txData]; //數(shù)據(jù)設(shè)置
[self.chartView animateWithYAxisDuration:1]; //設(shè)置動畫效果
}
//數(shù)據(jù)設(shè)置
-(BarChartData *)txData
{
int xValues=12; //X軸上要顯示多少條數(shù)據(jù)
double maxY=100;// Y軸的最大值
//X軸上面需要顯示的數(shù)據(jù)
NSMutableArray *xV=[[NSMutableArray alloc]init];
for (int i=0; i<xValues; i++) {
[xV addObject:[NSString stringWithFormat:@"%d",I]];
}
//對應(yīng)Y軸上面需要顯示的數(shù)據(jù)
NSMutableArray *yV=[[NSMutableArray alloc]init];
for (int i=0; i<xValues; i++) {
double mult=maxY+1;
double val=(double)(arc4random_uniform(mult));
BarChartDataEntry *entry=[[BarChartDataEntry alloc]initWithX:i y:val];
[yV addObject:entry];
}
//創(chuàng)建BarChartDataSet對象,其中包含有Y軸數(shù)據(jù)信息,以及可以設(shè)置柱形樣式
BarChartDataSet *set1=[[BarChartDataSet alloc]initWithValues:yV label:nil];
// set1.barSpace = 0.2;//柱形之間的間隙占整個柱形(柱形+間隙)的比例
set1.drawValuesEnabled = YES;//是否在柱形圖上面顯示數(shù)值
set1.highlightEnabled = YES;//點擊選中柱形圖是否有高亮效果,(雙擊空白處取消選中)
[set1 setColors:ChartColorTemplates.material];//設(shè)置柱形圖顏色
//將BarChartDataSet對象放入數(shù)組中
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
//創(chuàng)建BarChartData對象, 此對象就是barChartView需要最終數(shù)據(jù)對象
BarChartData *data=[[BarChartData alloc]initWithDataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];//文字字體
[data setValueTextColor:[UIColor orangeColor]];//文字顏色
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
//自定義數(shù)據(jù)顯示格式
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setPositiveFormat:@"#0.0"];
//[data setValueFormatter:formatter];
return data;
}
效果如圖

實例3 餅狀圖
-(void)pieInit{
self.pieChartView=[[PieChartView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
self.pieChartView.delegate=self;
[self.view addSubview:self.pieChartView];
[self.pieChartView setExtraOffsetsWithLeft:5 top:10 right:70 bottom:5];//餅狀圖距離邊緣的間隙
self.pieChartView.usePercentValuesEnabled = YES;//是否根據(jù)所提供的數(shù)據(jù), 將顯示數(shù)據(jù)轉(zhuǎn)換為百分比格式
self.pieChartView.dragDecelerationEnabled = YES;//拖拽餅狀圖后是否有慣性效果
self.pieChartView.drawSlicesUnderHoleEnabled= NO;//如果是的話,這個洞會穿透到薄片的內(nèi)部尖端
self.pieChartView.chartDescription.enabled = NO;//餅狀圖描述
self.pieChartView.drawHoleEnabled = YES;//餅狀圖是否是空心
self.pieChartView.holeRadiusPercent = 0.5;//空心半徑占比
self.pieChartView.holeColor = [UIColor clearColor];//空心顏色
self.pieChartView.transparentCircleRadiusPercent = 0.55;//半透明空心半徑占比
self.pieChartView.transparentCircleColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.3];//半透明空心的顏色
if (self.pieChartView.isDrawHoleEnabled == YES) {
self.pieChartView.drawCenterTextEnabled = YES;//是否顯示中間文字
//普通文本
// self.pieChartView.centerText = @"餅狀圖";//中間文字
//富文本
NSMutableAttributedString *centerText = [[NSMutableAttributedString alloc] initWithString:@"餅狀圖bbb\n餅狀圖aaa"];
[centerText setAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:16],
NSForegroundColorAttributeName: [UIColor orangeColor]}
range:NSMakeRange(0, centerText.length)];
self.pieChartView.centerAttributedText = centerText;
}
self.pieChartView.legend.maxSizePercent = 1;//圖例在餅狀圖中的大小占比, 這會影響圖例的寬高
self.pieChartView.legend.formToTextSpace = 5;//文本間隔
self.pieChartView.legend.font = [UIFont systemFontOfSize:10];//字體大小
self.pieChartView.legend.textColor = [UIColor grayColor];//字體顏色
// self.pieChartView.legend.position = ChartLegendPositionBelowChartCenter;//圖例在餅狀圖中的位置
self.pieChartView.legend.horizontalAlignment = ChartLegendHorizontalAlignmentRight;
self.pieChartView.legend.verticalAlignment = ChartLegendVerticalAlignmentTop;
self.pieChartView.legend.orientation = ChartLegendOrientationVertical;
self.pieChartView.legend.form = ChartLegendFormCircle;//圖示樣式: 方形、線條、圓形
self.pieChartView.legend.formSize = 8;//圖示大小
[self.pieChartView setRotationEnabled:false];//禁止拖拽
[self pieData];
}
-(PieChartData *)pieData
{
//每個區(qū)塊的數(shù)據(jù)
//每個區(qū)塊的名稱或描述
NSMutableArray *arr = [[NSMutableArray alloc]init];
NSMutableArray *nameArr = [[NSMutableArray alloc]init];
[arr addObject:@"6"];
[arr addObject:@"7"];
[arr addObject:@"2"];
[arr addObject:@"4"];
[nameArr addObject:@"A"];
[nameArr addObject:@"B"];
[nameArr addObject:@"C"];
[nameArr addObject:@"D"];
NSMutableArray *values = [[NSMutableArray alloc] init];
// IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex (even if from different DataSets), since no values can be drawn above each other.
for (int i = 0; i < arr.count; I++)
{
NSString * aaa = arr[i];
double bb = aaa.doubleValue;
[values addObject:[[PieChartDataEntry alloc] initWithValue: bb label: nameArr[i]]];
}
//dataSet
PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithValues:values label:@"aaaf"];
dataSet.drawValuesEnabled = YES;//是否繪制顯示數(shù)據(jù)
NSMutableArray *colors = [[NSMutableArray alloc] init];
[colors addObjectsFromArray:ChartColorTemplates.vordiplom];
[colors addObjectsFromArray:ChartColorTemplates.joyful];
[colors addObjectsFromArray:ChartColorTemplates.colorful];
[colors addObjectsFromArray:ChartColorTemplates.liberty];
[colors addObjectsFromArray:ChartColorTemplates.pastel];
[colors addObject:[UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f]];
dataSet.colors = colors;//區(qū)塊顏色
dataSet.sliceSpace = 5;//相鄰區(qū)塊之間的間距
dataSet.selectionShift = 8;//選中區(qū)塊時, 放大的半徑
dataSet.xValuePosition = PieChartValuePositionInsideSlice;//名稱位置
dataSet.yValuePosition = PieChartValuePositionOutsideSlice;//數(shù)據(jù)位置
//數(shù)據(jù)與區(qū)塊之間的用于指示的折線樣式
dataSet.valueLinePart1OffsetPercentage = 0.85;//折線中第一段起始位置相對于區(qū)塊的偏移量, 數(shù)值越大, 折線距離區(qū)塊越遠
dataSet.valueLinePart1Length = 0.5;//折線中第一段長度占比
dataSet.valueLinePart2Length = 0.4;//折線中第二段長度最大占比
dataSet.valueLineWidth = 1;//折線的粗細
dataSet.valueLineColor = [UIColor brownColor];//折線顏色
//data
PieChartData *data = [[PieChartData alloc] initWithDataSet:dataSet];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterPercentStyle;
formatter.maximumFractionDigits = 0;//小數(shù)位數(shù)
formatter.multiplier = @1.f;
[data setValueFormatter:[[ChartDefaultValueFormatter alloc] initWithFormatter:formatter]];//設(shè)置顯示數(shù)據(jù)格式
[data setValueTextColor:[UIColor brownColor]];
[data setValueFont:[UIFont systemFontOfSize:10]];
self.pieChartView.data = data;
[ self.pieChartView setNeedsDisplay];
return data;
}
//效果如何

實例4 復(fù)合圖
/*復(fù)合圖/
-(void)comInit{
self.comView=[[CombinedChartView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
self.comView.delegate=self;
[self.view addSubview:self.comView];
self.comView.doubleTapToZoomEnabled=NO;//取消雙擊放大
self.comView.scaleXEnabled=YES; //設(shè)置X軸縮放
self.comView.scaleYEnabled=YES;//設(shè)置Y軸縮放
self.comView.dragDecelerationEnabled = YES;//拖拽后是否有慣性效果
self.comView.dragDecelerationFrictionCoef = 0.9;//拖拽后慣性效果的摩擦系數(shù)(0~1),數(shù)值越小,慣性越不明顯
self.comView.highlightPerTapEnabled = NO;//取消單擊高亮顯示
self.comView.highlightPerDragEnabled = NO;//取消拖拽高亮
//設(shè)置X軸的樣式
ChartXAxis *xAxis=self.comView.xAxis;
xAxis.axisLineWidth=1; //X軸的線寬
xAxis.labelPosition = XAxisLabelPositionBottom;//X軸的顯示位置,默認是顯示在上面的
xAxis.drawGridLinesEnabled = NO;//不繪制網(wǎng)格線
xAxis.labelCount=12; //label的個數(shù)
//xAxis. = 4;//設(shè)置label間隔,若設(shè)置為1,則如果能全部顯示,則每個柱形下面都會顯示label
//xAxis.spaceMin=0;
// xAxis.spaceMax=1;
xAxis.labelTextColor = [UIColor brownColor];//label文字顏色
//設(shè)置Y軸的樣式
self.comView.rightAxis.enabled=NO; //不繪制右邊軸
ChartYAxis *leftAxis=self.comView.leftAxis;
leftAxis.forceLabelsEnabled = NO;//不強制繪制制定數(shù)量的label
leftAxis.axisMinimum = 0;//設(shè)置Y軸的最小值
leftAxis.drawZeroLineEnabled = YES;//從0開始繪制
leftAxis.axisMaximum = 105;//設(shè)置Y軸的最大值
leftAxis.inverted = NO;//是否將Y軸進行上下翻轉(zhuǎn)
leftAxis.axisLineWidth = 0.5;//Y軸線寬
// leftAxis.axisMinLabels=1; //軸上標簽的最小數(shù)目
//leftAxis.axisMaxLabels=100;//軸上標簽的最大數(shù)目
leftAxis.axisLineColor = [UIColor blackColor];//Y軸顏色
leftAxis.labelCount = 5; //通過labelCount屬性設(shè)置Y軸要均分的數(shù)量.設(shè)置的labelCount的值不一定就是Y軸要均分的數(shù)量,這還要取決于forceLabelsEnabled屬性,
leftAxis.forceLabelsEnabled = NO; //如果forceLabelsEnabled等于YES, 則強制繪制指定數(shù)量的label, 但是可能不是均分的
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
leftAxis.labelTextColor = [UIColor brownColor];//文字顏色
leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字體
// 設(shè)置Y軸上標簽顯示數(shù)字的格式,代碼如下:
//leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];//自定義格式
//leftAxis.valueFormatter.pos = @" $";//數(shù)字后綴單位
// 設(shè)置Y軸上網(wǎng)格線的樣式,代碼如下:
leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//設(shè)置虛線樣式的網(wǎng)格線
leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//網(wǎng)格線顏色
leftAxis.gridAntialiasEnabled = YES;//開啟抗鋸齒
//設(shè)置限制線
ChartLimitLine *limitLine = [[ChartLimitLine alloc] initWithLimit:80 label:@"限制線"];
limitLine.lineWidth = 2;
limitLine.lineColor = [UIColor greenColor];
limitLine.lineDashLengths = @[@5.0f, @5.0f];//虛線樣式
limitLine.labelPosition = ChartLimitLabelPositionRightTop;//位置
[leftAxis addLimitLine:limitLine];//添加到Y(jié)軸上
leftAxis.drawLimitLinesBehindDataEnabled = YES;//設(shè)置限制線繪制在柱形圖的后面
self.comView.legend.enabled=NO; //不顯示圖利說明
[self.comView animateWithYAxisDuration:1];
//設(shè)置數(shù)據(jù)
CombinedChartData *comData=[[CombinedChartData alloc]init];
comData.barData=[self txData];
comData.lineData=[self zxData];
self.comView.data=comData;
}
效果圖

