高度自定義圖表庫HLChartView

weixin_33866037發表於2017-08-04

chart gif GitHub地址HLChartView

2407050-c65a6736bb66677d.gif


cocoa pods 使用

pod 'HLChartView'

1.折線圖或曲線圖 HLLineChartView

/** y軸值,必傳 */

@property(nonatomic,strong) NSArray*yValueLabels;  

 /** x軸座標,必傳 */

@property(nonatomic,strong) NSArray*xLabels


如何使用

HLLineChartView *lineChartView = [[HLLineChartView alloc]initWithFrame:CGRectMake(0, 100, kScreen_Width, 300)];

NSArray *arr1 = @[@"3",@"4.3",@"10.2",@"5",@"15",@"3",@"4.3",@"10.2",@"5",@"1"];

NSArray *arr2 = @[@"2",@"6.3",@"6.2",@"15",@"10",@"2",@"14.3",@"5.2",@"11",@"4"];

HLLineChartData *data1 = [HLLineChartData lineChartDataWithValuesArray:arr1 lineColor:[UIColor redColor]];

data1.yValuesColor = [UIColor greenColor];

data1.lineWidth = 3.0f;

data1.circleSize = 5;

data1.circleType = HLLineDataCircleTypeCircle;

HLLineChartData *data2 = [HLLineChartData lineChartDataWithValuesArray:arr2 lineColor:[UIColor blueColor]];

lineChartView.yValueLabels = @[data1,data2];

lineChartView.xLabels = @[@"中通快遞123",@"圓通快遞1",@"順豐快遞1222222222222222222222222",@"郵政快遞2111",@"韻達快遞22222",@"中通快遞11111",@"圓通快遞",@"順豐快遞",@"郵政快遞",@"韻達快遞"];

[self.view addSubview:lineChartView];

lineChartView.yLablesColor = [UIColor greenColor];

lineChartView.xLabelsColor = [UIColor blueColor];

//    lineChartView.lineChartType = HLLineChartTypeBrokenLine;

lineChartView.ySepLabelCount = 10;

//    lineChartView.xLabelsWidth = 30;

//    lineChartView.xLabelsHeight = 20;

//    lineChartView.lineColor = [UIColor brownColor];

//    lineChartView.isHideYLabels = YES;

//    lineChartView.isHideXLables = YES;

lineChartView.isShowGradientColor = NO;

//    lineChartView.isShowXSepratorLine = NO;

//    lineChartView.isShowYSepratorLine = NO;

//    lineChartView.isAnimatedDisplay = NO;

[lineChartView strokeStart];

2.餅圖HLPieChartView

如何使用

HLPieChartData *data1 = [HLPieChartData pieDataWithValue:@"20" pieChartColor:[UIColor redColor] detailText:@"中通快遞"];

HLPieChartData *data2 = [HLPieChartData pieDataWithValue:@"10.2" pieChartColor:[UIColor blueColor] detailText:@"韻達快遞"];

HLPieChartData *data3 = [HLPieChartData pieDataWithValue:@"30.33" pieChartColor:[UIColor purpleColor] detailText:@"圓通快遞"];

HLPieChartData *data4 = [HLPieChartData pieDataWithValue:@"5" pieChartColor:[UIColor greenColor] detailText:@"順豐快遞"];

HLPieChartData *data5 = [HLPieChartData pieDataWithValue:@"8" pieChartColor:[UIColor cyanColor] detailText:@"郵政快遞"];

HLPieChartView *pieChart = [[HLPieChartView alloc]initWithFrame:CGRectMake(0, 64, kScreen_Width, kScreen_Width)];

pieChart.pieDatas = @[data1,data2,data3,data4,data5];

pieChart.outerCircleRadius = 120;

pieChart.interCircleRadius = 40;

//    pieChart.isAnimatedDisplay = NO;

pieChart.lengendPosition = HLPieLengendPositionBottom;

//    pieChart.pieDetailTextType = HLPieDetailTextTypeValue;

//    pieChart.showLengendView = NO;

pieChart.titleText = @"這是今天收到的快遞";

[pieChart strokeStart];

[self.view addSubview:pieChart];


3.可自定義單級多級柱狀圖

如何使用

HLHistogramData *data1 = [HLHistogramData histogramDataWithValue:@"100" histogramColor:[UIColor redColor]];

HLHistogramData *data2 = [HLHistogramData histogramDataWithValue:@"30" histogramColor:[UIColor blueColor]];

HLHistogramData *data3 = [HLHistogramData histogramDataWithValue:@"50" histogramColor:[UIColor greenColor]];

HLHistogramData *data4 = [HLHistogramData histogramDataWithValue:@"120" histogramColor:[UIColor purpleColor]];

HLHistogramData *data11 = [HLHistogramData histogramDataWithValue:@"80" histogramColor:[UIColor redColor]];

HLHistogramData *data22 = [HLHistogramData histogramDataWithValue:@"20" histogramColor:[UIColor blueColor]];

HLHistogramData *data33 = [HLHistogramData histogramDataWithValue:@"165" histogramColor:[UIColor greenColor]];

HLHistogramData *data44 = [HLHistogramData histogramDataWithValue:@"60" histogramColor:[UIColor purpleColor]];

HLHistogramView *histogramView = [[HLHistogramView alloc]initWithFrame:CGRectMake(0, 100, kScreen_Width, 300)];

histogramView.yValueLabels = @[@[data1,data2,data3],@[data1,data2,data3,data4],@[data11,data22],@[data33,data44],@[data11,data22,data33,data44],@[data1,data2,data33,data44]];

histogramView.xLabels = @[@"1月底層、架構、音視訊、逆向",@"2月底視訊逆向",@"3月底層、音視訊、逆向",@"4月底層、音視訊、逆向",@"5月底層、架構、音視訊、逆向",@"6月底層"];

histogramView.xHistogramMinGap = 0;

//    histogramView.xHistogramMaxGap = 40;

//    histogramView.histogramWidth = 30;

//    histogramView.ySepLabelCount = 6;

//    histogramView.yLabelWidth = 50;

[histogramView strokeStart];

[self.view addSubview:histogramView];


使用問題,請賜教,萬分感謝

相關文章