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
0 commit comments