您的位置:首页 > 移动开发 > IOS开发

iOS中的图表(AAChart)使用

2017-06-13 13:49 597 查看
https://github.com/potato512/AAChartKit

效果图:




   

 
 


   



   



   



   



   


代码示例:

// 头文件
#import "UIChartView.h"
// 定义成属性
@property (nonatomic, strong) UIChartView *chartView;

// 实例化
self.chartView = [[UIChartView alloc] initWithFrame:CGRectMake(0.0, height, self.view.frame.size.width, (self.view.frame.size.height - height)) view:self.view];

// 类型
self.chartView.chartModel.chartTypeSet(AAChartTypeBar);


// 标题,数据等设置
self.chartView.chartTitle = @"编程语言热度";
self.chartView.chartSubTitle = @"虚拟数据";
self.chartView.chartXTitles = @[@"Java", @"Swift", @"Python", @"Objective-C", @"PHP", @"Go"];
self.chartView.chartYTitle = @"摄氏度";
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < 4; i++)
{
ChartModel *model = [ChartModel new];
if (0 == i)
{
model.name = @"2014";
model.datas = @[@45, @88, @49, @43, @65, @56];
}
else if (1 == i)
{
model.name = @"2015";
model.datas = @[@31, @22, @33, @54, @35, @36];
}
else if (2 == i)
{
model.name = @"2016";
model.datas = @[@11, @12, @13, @14, @15, @16];
}
else if (3 == i)
{
model.name = @"2017";
model.datas = @[@21, @22, @24, @27, @25, @26];
}

[array addObject:model];
}
self.chartView.charts = array;

// 刷新数据,显示图表
[self.chartView reloadChart];

// 其他属性设置
// 是否显示加载状态
self.chartView.showActivityIndicatorView = YES;

// 堆叠类型
NSArray *stackingArr = @[AAChartStackingTypeFalse, AAChartStackingTypeNormal, AAChartStackingTypePercent];
self.chartView.chartModel.stacking = stackingArr[segmentedControl.selectedSegmentIndex];

// 折线连接点形状
NSArray *symbolArr = @[AAChartSymbolTypeCircle, AAChartSymbolTypeSquare, AAChartSymbolTypeDiamond, AAChartSymbolTypeTriangle, AAChartSymbolTypeTriangle_down];
self.chartView.chartModel.symbol = symbolArr[segmentedControl.selectedSegmentIndex];

// x轴翻转
self.chartView.chartModel.xAxisReversed = (switchView.on ? true : false);

// y轴翻转
self.chartView.chartModel.yAxisReversed = (switchView.on ? true : false);

// x轴直立
self.chartView.chartModel.inverted = (switchView.on ? true : false);

// 从中心向四周辐射
self.chartView.chartModel.polar = (switchView.on ? true : false);

// 隐藏连接点
self.chartView.chartModel.markerRadius = (switchView.on ? @0 : @5);

// 显示数据点
self.chartView.chartModel.dataLabelEnabled = (switchView.on ? true : false);

// 刷新数据,重新绘制图表
[self.chartView refreshChart];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: