iOS的折线图:ARLineChart

jopen 11年前

ARLineChart是一个iOS的折线图,使用Objective-C编写。适用于需要有双Y轴的应用场景。 x轴和y轴可以放大和缩小,可以滚动,双击可以还原原始大小。

如何使用?

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];

iOS曲线图:ARLineChart iOS曲线图:ARLineChart

项目主页:http://www.open-open.com/lib/view/home/1392900052531