1.柱状图
CGFloat chartViewWidth = self.view.frame.size.width;
AAChartView *aaChartView = [[AAChartView alloc] init];
aaChartView.frame = CGRectMake(0.0f, 60.0f, chartViewWidth, 300);
[self.view addSubview:aaChartView];
AAChartModel *aaChartModel = AAObject(AAChartModel)
.chartTypeSet(AAChartTypeColumn) // 设置图表类型
.titleSet(@"编程语言热度") // 图表标题
.subtitleSet(@"单位(%)") // 图表副标题
.categoriesSet(@[@"C",@"C++",@"Objective-C",@"Swift", @"PHP",@"Java"]) // 图标横幅内容
.yAxisTitleSet(@"") // y轴单位
.seriesSet(@[
AAObject(AASeriesElement)
.nameSet(@"2018")
.dataSet(@[@7.0, @6.9, @9.5, @14.5, @18.2, @21.5]),
]);
[aaChartView aa_drawChartWithChartModel:aaChartModel];
-
不同颜色
CGFloat chartViewWidth = self.view.frame.size.width;
AAChartView *aaChartView = [[AAChartView alloc] init];
aaChartView.frame = CGRectMake(0.0f, 60.0f, chartViewWidth, 300);
[self.view addSubview:aaChartView];
AAChartModel *aaChartModel = AAChartModel.new
.chartTypeSet(AAChartTypeColumn)
.stackingSet(AAChartStackingTypeNormal)
.titleSet(@"")
.subtitleSet(@"")
.yAxisTitleSet(@"")
.colorsThemeSet(@[@"#fe117c",@"#7dffc0",@"#06caf4",@"#ffc069"])
.categoriesSet(@[@"广东",@"广西",@"湖南",@"上海"])
.seriesSet(@[
AASeriesElement.new
.nameSet(@"重要")
.dataSet(@[@15, @7, @9, @9]),
AASeriesElement.new
.nameSet(@"一般")
.dataSet(@[@13, @9, @7, @10]),
AASeriesElement.new
.nameSet(@"提示")
.dataSet(@[@13, @24, @7, @9]),
AASeriesElement.new
.nameSet(@"紧急")
.dataSet(@[@11, @3, @25, @8]),
]);
[aaChartView aa_drawChartWithChartModel:aaChartModel];
-
颜色渐变条形图
CGFloat chartViewWidth = self.view.frame.size.width;
AAChartView *aaChartView = [[AAChartView alloc] init];
aaChartView.frame = CGRectMake(0.0f, 60.0f, chartViewWidth, 300);
[self.view addSubview:aaChartView];
NSDictionary *gradientColorDic =
@{
@"linearGradient": @{
@"x1": @0,
@"y1": @1,
@"x2": @0,
@"y2": @0
},
@"stops": @[@[@0,@"#8A2BE2"],
@[@1,@"#1E90FF"]]//颜色字符串设置支持十六进制类型和 rgba 类型
};
AAChartModel *aaChartModel = AAChartModel.new
.chartTypeSet(AAChartTypeBar) // 颜色渐变
.invertedSet(YES)
.titleSet(@"颜色渐变")
.subtitleSet(@"")
.xAxisReversedSet(true)
.categoriesSet(@[@"广东",@"广西",@"湖南",@"上海"])
.seriesSet(@[
AASeriesElement.new
.nameSet(@"")
.dataSet(@[@15, @7, @9, @9])
.colorSet((id)gradientColorDic)
]);
[aaChartView aa_drawChartWithChartModel:aaChartModel];
-
折线图
CGFloat chartViewWidth = self.view.frame.size.width;
AAChartView *aaChartView = [[AAChartView alloc] init];
aaChartView.frame = CGRectMake(0.0f, 60.0f, chartViewWidth, 300);
[self.view addSubview:aaChartView];
AAChartModel *aaChartModel = AAChartModel.new
.chartTypeSet(AAChartTypeLine) // 折线
.symbolSet(AAChartSymbolTypeCircle)
.titleSet(@"折线图")
.subtitleSet(@"")
.yAxisTitleSet(@"")
.colorsThemeSet(@[@"#fe117c",@"#ffc069",@"#06caf4",@"#7dffc0"])//设置主体颜色数组
.categoriesSet(@[@"广东",@"广西",@"湖南",@"上海"])
.seriesSet(@[
AASeriesElement.new
.nameSet(@"<1年")
.dataSet(@[@7.0, @6.9, @9.5, @14.5]),
AASeriesElement.new
.nameSet(@"1-3年")
.dataSet(@[@0.2, @0.8, @5.7, @11.3]),
AASeriesElement.new
.nameSet(@"3-5年")
.dataSet(@[@1, @0.6, @3.5, @8.4]),
AASeriesElement.new
.nameSet(@"5-8年")
.dataSet(@[@3.9, @4.2, @5.7, @8.5]),
]);
[aaChartView aa_drawChartWithChartModel:aaChartModel];