折线图图表(Chart)效果源码
源码ARLineChart,ARLineChart是一个iOS的折线图,使用Objective-C编写。适用于需要有双Y轴的应用场景。 x轴和y轴可以放大和缩小,可以滚动,双击可以还原原始大小。实现具有双Y轴的折线统计图,可以左右滚动折线图,x轴和y轴可以放大和缩小,双击可以还原原始大小。 ARLineChart is a line char view on iOS , written using Objective-C . There are scenarios for applications requiring dual- Y axis. x -axis and y-axis can zoom in and out , you can scroll , double-click can restore the original size. 使用方法: 1、将“ARLineChart”文件夹内所有文件加入到工程中即可。 2、在需要的地方引入头文件: #import "ARLineChartView.h" #import "ARLineChartCommon.h" 3、初始化数据源,例如: NSMutableArray *dataSource = [NSMutableArray array]; double distanceMin = 0, distanceMax = 100; double altitudeMin = 5.0, altitudeMax = 50; double speedMin = 0.5, speedMax = 15; srand(time(NULL)); //Random seed for (int i=0; i< 11; i++) { ARLineChartItem *item = [[ARLineChartItem alloc] init]; double randVal; randVal = rand() /((double)(RAND_MAX)/distanceMax) + distanceMin; item.xValue = randVal; randVal = rand() /((double)(RAND_MAX)/altitudeMax) + altitudeMin; item.y1Value = randVal; randVal = rand() /((double)(RAND_MAX)/speedMax) + speedMin; item.y2Value = randVal; NSLog(@"Random: item.xValue=%.2lf, item.y1Value=%.2lf, item.y2Value=%.2lf", item.xValue, item.y1Value, item.y2Value); [dataSource addObject:item]; } 4、初始化折线图视图: CGRect rect = CGRectMake (5, 40, self.view.frame.size.width - 5 - 5, 300); self.lineChartView = [[ARLineChartView alloc] initWithFrame: rect dataSource: dataSource xTitle: @ "Kilometre" y1Title: @ "Altitude (meters)" y2Title: @ "Speed (km / h)" desc1: @ "Altitude" desc2: @ "Speed"]; [self.view addSubview: self.lineChartView];
用户评论