Skip to content

Commit dd7fcbe

Browse files
committed
Optimize the chart rendering animation types sample
1 parent d044625 commit dd7fcbe

7 files changed

Lines changed: 117 additions & 32 deletions

File tree

AAChartKitDemo/ChartsDemo/ChartAnimationTypeVC.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@
3232

3333
#import <UIKit/UIKit.h>
3434

35+
typedef NS_ENUM(NSInteger,ChartAnimationTypeVCChartType) {
36+
ChartAnimationTypeVCChartTypeColumn = 0,
37+
ChartAnimationTypeVCChartTypeBar,
38+
ChartAnimationTypeVCChartTypeArea,
39+
ChartAnimationTypeVCChartTypeAreaspline,
40+
ChartAnimationTypeVCChartTypeLine,
41+
ChartAnimationTypeVCChartTypeSpline,
42+
ChartAnimationTypeVCChartTypeStepLine,
43+
ChartAnimationTypeVCChartTypeStepArea,
44+
ChartAnimationTypeVCChartTypeScatter,
45+
};
46+
3547
@interface ChartAnimationTypeVC : UIViewController
3648

49+
@property (nonatomic, assign) ChartAnimationTypeVCChartType chartType;
50+
3751
@end

AAChartKitDemo/ChartsDemo/ChartAnimationTypeVC.m

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@
3333
#import "ChartAnimationTypeVC.h"
3434
#import "AAChartKit.h"
3535

36-
#define CurrentHeight ([UIScreen mainScreen].bounds.size.height)
37-
#define CurrentWidth ([UIScreen mainScreen].bounds.size.width)
3836
#define ColorWithRGB(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
3937
#define KBlueColor ColorWithRGB(63, 153,231,1)
4038

41-
@interface ChartAnimationTypeVC ()<UITableViewDelegate,UITableViewDataSource> {
42-
UIButton *_lastClickedBtn;
43-
}
39+
@interface ChartAnimationTypeVC ()<UITableViewDelegate,UITableViewDataSource>
4440

4541
@property (nonatomic, strong) AAChartModel *chartModel;
4642
@property (nonatomic, strong) AAChartView *chartView;
@@ -55,36 +51,111 @@ - (void)viewDidLoad {
5551
[super viewDidLoad];
5652
self.view.backgroundColor = [UIColor whiteColor];
5753
self.title = @"动画类型";
54+
55+
AAChartType chartType = [self configureTheChartType];
5856

5957
[self configureTheAnimationTypeTableView];
60-
[self configureTheChartView];
58+
[self configureTheChartViewWithChartType:chartType];
6159

6260
}
6361

64-
- (void)configureTheChartView {
62+
- (AAChartType)configureTheChartType {
63+
switch (self.chartType) {
64+
case 0:
65+
return AAChartTypeColumn;
66+
case 1:
67+
return AAChartTypeBar;
68+
case 2:
69+
return AAChartTypeArea;
70+
case 3:
71+
return AAChartTypeAreaspline;
72+
case 4:
73+
return AAChartTypeLine;
74+
case 5:
75+
return AAChartTypeSpline;
76+
case 6:
77+
return AAChartTypeLine;
78+
case 7:
79+
return AAChartTypeArea;
80+
case 8:
81+
return AAChartTypeScatter;
82+
}
83+
}
84+
85+
- (void)configureTheChartViewWithChartType:(AAChartType)chartType {
6586
self.chartView = [[AAChartView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width-115, self.view.frame.size.height-60)];
6687
self.view.backgroundColor = [UIColor whiteColor];
6788
self.chartView.scrollEnabled = NO;
6889
// self.chartView.contentHeight = self.view.frame.size.height-220;
6990
[self.view addSubview:self.chartView];
7091

71-
self.chartModel= AAObject(AAChartModel)
72-
.chartTypeSet(AAChartTypeColumn)
92+
self.chartModel = AAObject(AAChartModel)
93+
.chartTypeSet(chartType)
7394
.animationDurationSet(@1500)
7495
.titleSet(@"")
75-
.borderRadiusSet(@3)
7696
.subtitleSet(@"")
7797
.categoriesSet(@[@"Java",@"Swift",@"Python",@"Ruby", @"PHP",@"Go",@"C",@"C#",@"C++",@"Perl",@"R",@"MATLAB",@"SQL"])
7898
.yAxisTitleSet(@"")
79-
.seriesSet(@[
80-
AAObject(AASeriesElement)
81-
.nameSet(@"2017")
82-
.dataSet(@[@45,@88,@49,@43,@65,@56,@47,@28,@49,@44,@89,@55]),
83-
]
84-
)
85-
8699
;
87-
[self.chartView aa_drawChartWithChartModel:_chartModel];
100+
101+
if (self.chartType == ChartAnimationTypeVCChartTypeStepArea
102+
|| self.chartType == ChartAnimationTypeVCChartTypeStepLine) {
103+
self.chartModel
104+
.gradientColorEnabledSet(true)
105+
.markerRadiusSet(@0)
106+
.seriesSet(@[
107+
AAObject(AASeriesElement)
108+
.nameSet(@"2017")
109+
.dataSet(@[@7.0, @6.9, @9.5, @14.5, @18.2, @21.5, @25.2, @26.5, @23.3, @18.3, @13.9, @9.6])
110+
.stepSet((id)@(true))
111+
,
112+
]
113+
);
114+
} else if (self.chartType == ChartAnimationTypeVCChartTypeArea
115+
|| self.chartType == ChartAnimationTypeVCChartTypeAreaspline) {
116+
NSDictionary *gradientColorDic = @{
117+
@"linearGradient": @{
118+
@"x1": @0,
119+
@"y1": @1,
120+
@"x2": @0,
121+
@"y2": @0
122+
},
123+
@"stops": @[@[@0,@"rgba(255,140,0,0.2)"],
124+
@[@1,@"rgba(220,20,60,1)"]]//颜色字符串设置支持十六进制类型和 rgba 类型
125+
};
126+
self.chartModel
127+
.markerRadiusSet(@0)
128+
.gradientColorEnabledSet(true)
129+
.seriesSet(@[
130+
AAObject(AASeriesElement)
131+
.nameSet(@"2017")
132+
.dataSet(@[@0.9, @0.6, @3.5, @8.4, @13.5, @17.0, @18.6, @17.9, @14.3, @9.0, @3.9, @1.0])
133+
.colorSet((id)gradientColorDic)
134+
,
135+
]);
136+
} else {
137+
NSDictionary *gradientColorDic = @{
138+
@"linearGradient": @{
139+
@"x1": @0,
140+
@"y1": @0,
141+
@"x2": @0,
142+
@"y2": @1
143+
},
144+
@"stops": @[@[@0,@"#8A2BE2"],
145+
@[@1,@"#1E90FF"]]//颜色字符串设置支持十六进制类型和 rgba 类型
146+
};
147+
148+
self.chartModel
149+
.seriesSet(@[
150+
AAObject(AASeriesElement)
151+
.nameSet(@"2017")
152+
.dataSet(@[@3.9, @4.2, @5.7, @8.5, @11.9, @15.2, @17.0, @16.6, @14.2, @10.3, @6.6, @4.8])
153+
.colorSet((id)gradientColorDic)
154+
,
155+
]);
156+
}
157+
158+
[self.chartView aa_drawChartWithChartModel:self.chartModel];
88159
}
89160

90161
- (void)configureTheAnimationTypeTableView {
@@ -121,10 +192,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
121192
- (void)animationTypeTableViewClicked:(AAChartAnimation)chartAnimationType {
122193
self.chartModel.animationType = chartAnimationType;
123194
[self.chartView aa_refreshChartWithChartModel:self.chartModel];//刷新图表数据
124-
_lastClickedBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
125-
_lastClickedBtn.backgroundColor = [UIColor whiteColor];
126-
[_lastClickedBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
127-
128195
}
129196

130197
- (NSArray *)animationTypeArr {
@@ -168,8 +235,6 @@ - (NSArray *)animationTypeArr {
168235
];
169236
}
170237
return _animationTypeArr;
171-
}
172-
173-
238+
}
174239

175240
@end

AAChartKitDemo/ChartsDemo/DrawChartWithAAOptionsVC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ - (AAOptions *)configureChartWithBackgroundImage {
617617
;
618618

619619
AAOptions *aaOptions = [AAOptionsConstructor configureChartOptionsWithAAChartModel:aaChartModel];
620-
aaOptions.chart.plotBackgroundImage = @"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1138516915,1273515241&fm=27&gp=0.jpg";
620+
aaOptions.chart.plotBackgroundImage = @"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2859216016,2109779587&fm=27&gp=0.jpg";
621621
return aaOptions;
622622
}
623623

AAChartKitDemo/ChartsDemo/FirstViewController.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ - (void)viewDidLoad {
6969
self.title = @"AAChartKit";
7070
self.view.backgroundColor = [UIColor whiteColor];
7171

72-
73-
7472
[self configTheTableView];
7573

7674
#warning revise
@@ -174,6 +172,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
174172
case 4: {
175173
/*JQuery动画样式类型演示*/
176174
ChartAnimationTypeVC *vc = [[ChartAnimationTypeVC alloc]init];
175+
vc.chartType = indexPath.row;
177176
[self.navigationController pushViewController:vc animated:YES];
178177
}
179178
break;
@@ -294,7 +293,14 @@ - (NSArray *)chartTypeNameArr {
294293
@[@"模拟实时更新数据示例"
295294
],
296295
/*JQuery动画样式类型演示*/
297-
@[@"图形动画样式相关演示"
296+
@[@"Column Chart---柱形图",
297+
@"Bar Chart---条形图",
298+
@"Area Chart---折线填充图",
299+
@"Areaspline Chart---曲线填充图",
300+
@"Line Chart---折线图",
301+
@"Spline Chart---曲线图",
302+
@"Step Line Chart--直方折线图",
303+
@"Step Area Chart--直方折线填充图",
298304
],
299305
/*通过AAOptions实例对象来绘制图形*/
300306
@[@"绘制legend居顶部的区域填充图",

AAChartKitDemo/ChartsDemo/MixedChartVC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ - (AAChartModel *)configureTheChartModel:(NSString *)chartType {
8888
@[@1248825600000, @10.8, @17.8],
8989
@[@1248912000000, @11.8, @18.5],
9090
@[@1248998400000, @10.8, @16.1]],
91-
@"type": @"areasplinerange",
91+
@"type": AAChartTypeArearange,
9292
@"lineWidth": @0,
9393
@"linkedTo": @":previous",
9494
@"fillOpacity": @0.4,

AAChartKitDemo/ChartsDemo/SecondViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#import <UIKit/UIKit.h>
3434

3535
typedef NS_ENUM(NSInteger,SecondeViewControllerChartType) {
36-
SecondeViewControllerChartTypeColumn =0,
36+
SecondeViewControllerChartTypeColumn = 0,
3737
SecondeViewControllerChartTypeBar,
3838
SecondeViewControllerChartTypeArea,
3939
SecondeViewControllerChartTypeAreaspline,

AAChartKitLib/AAChartConfiger/AAChartModel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (instancetype)init {
101101
_subtitleAlign = AAChartSubtitleAlignTypeLeft;//默认图表副标题居左显示
102102
_stacking = AAChartStackingTypeFalse;//默认不开启图表数据的堆积效果
103103
_zoomType = AAChartZoomTypeNone ;//默认禁用图表的手势缩放功能
104-
_colorsTheme = @[@"#9b43b4",@"#ef476f",@"#ffd066",@"#04d69f",@"#25547c",];//默认颜色主题
104+
_colorsTheme = @[@"#1e90ff",@"#ef476f",@"#ffd066",@"#04d69f",@"#25547c",];//默认颜色主题
105105
_tooltipEnabled = YES;//默认启用浮动提示框
106106
// _tooltipCrosshairs = YES;//默认启用准星线
107107
_xAxisLabelsEnabled = YES;//默认显示 X轴坐标点文字

0 commit comments

Comments
 (0)