|
| 1 | +// |
| 2 | +// DoubleChartsLinkedWorkVC.m |
| 3 | +// AAChartKitDemo |
| 4 | +// |
| 5 | +// Created by AnAn on 2020/1/27. |
| 6 | +// Copyright © 2020 AnAn. All rights reserved. |
| 7 | +//*************** ...... SOURCE CODE ...... *************** |
| 8 | +//***...................................................*** |
| 9 | +//*** https://github.com/AAChartModel/AAChartKit *** |
| 10 | +//*** https://github.com/AAChartModel/AAChartKit-Swift *** |
| 11 | +//***...................................................*** |
| 12 | +//*************** ...... SOURCE CODE ...... *************** |
| 13 | + |
| 14 | +/* |
| 15 | + |
| 16 | + * ------------------------------------------------------------------------------- |
| 17 | + * |
| 18 | + * 🌕 🌖 🌗 🌘 ❀❀❀ WARM TIPS!!! ❀❀❀ 🌑 🌒 🌓 🌔 |
| 19 | + * |
| 20 | + * Please contact me on GitHub,if there are any problems encountered in use. |
| 21 | + * GitHub Issues : https://github.com/AAChartModel/AAChartKit/issues |
| 22 | + * ------------------------------------------------------------------------------- |
| 23 | + * And if you want to contribute for this project, please contact me as well |
| 24 | + * GitHub : https://github.com/AAChartModel |
| 25 | + * StackOverflow : https://stackoverflow.com/users/12302132/codeforu |
| 26 | + * JianShu : https://www.jianshu.com/u/f1e6753d4254 |
| 27 | + * SegmentFault : https://segmentfault.com/u/huanghunbieguan |
| 28 | + * |
| 29 | + * ------------------------------------------------------------------------------- |
| 30 | + |
| 31 | + */ |
| 32 | + |
| 33 | +#import "DoubleChartsLinkedWorkVC2.h" |
| 34 | +#import "AAChartKit.h" |
| 35 | +@interface DoubleChartsLinkedWorkVC2 () |
| 36 | + |
| 37 | +@property (nonatomic, strong) AAChartView *aaChartView1; |
| 38 | +@property (nonatomic, strong) AAChartView *aaChartView2; |
| 39 | +@property (nonatomic, strong) NSArray *gradientColorsArr; |
| 40 | +@property (nonatomic, strong) NSDictionary *selectedColor; |
| 41 | + |
| 42 | + |
| 43 | +@end |
| 44 | + |
| 45 | +@implementation DoubleChartsLinkedWorkVC2 |
| 46 | + |
| 47 | +- (void)viewDidLoad { |
| 48 | + [super viewDidLoad]; |
| 49 | + self.title = @"Double Charts Linked Working---双表联动"; |
| 50 | + self.view.backgroundColor = [UIColor whiteColor]; |
| 51 | + |
| 52 | + [self setUpTheAAChartViewOne]; |
| 53 | + [self setUpTheAAChartViewTwo]; |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +//配置第一个 AAChartView |
| 58 | +- (void)setUpTheAAChartViewOne { |
| 59 | + CGFloat chartViewWidth = self.view.frame.size.width; |
| 60 | + CGFloat screenHeight = self.view.frame.size.height; |
| 61 | + CGRect frame = CGRectMake(0, 60, chartViewWidth, screenHeight / 2); |
| 62 | + AAChartView *aaChartView = [[AAChartView alloc]initWithFrame:frame]; |
| 63 | + aaChartView.scrollEnabled = NO; |
| 64 | + [self.view addSubview:aaChartView]; |
| 65 | + _aaChartView1 = aaChartView; |
| 66 | + [self setupChartViewHandler]; |
| 67 | + |
| 68 | + AAChartModel *aaChartModel = AAChartModel.new |
| 69 | + .chartTypeSet(AAChartTypeColumn) |
| 70 | + .categoriesSet(@[ |
| 71 | + @"oceanBlue", |
| 72 | + @"sanguine", |
| 73 | + @"lusciousLime", |
| 74 | + @"purpleLake", |
| 75 | + @"freshPapaya", |
| 76 | + @"ultramarine", |
| 77 | + @"pinkSugar", |
| 78 | + @"lemonDrizzle", |
| 79 | + @"victoriaPurple", |
| 80 | + @"springGreens", |
| 81 | + @"mysticMauve", |
| 82 | + @"reflexSilver", |
| 83 | + @"neonGlowColor", |
| 84 | + @"berrySmoothieColor", |
| 85 | + @"newLeaf", |
| 86 | + @"cottonCandy", |
| 87 | + @"pixieDust", |
| 88 | + @"fizzyPeach", |
| 89 | + @"sweetDream", |
| 90 | + @"firebrick", |
| 91 | + @"wroughtIron", |
| 92 | + @"deepSea", |
| 93 | + @"coastalBreeze", |
| 94 | + @"eveningDelight", |
| 95 | + ]) |
| 96 | + .tooltipEnabledSet(false) |
| 97 | + .borderRadiusSet(@3) |
| 98 | + .legendEnabledSet(false) |
| 99 | + .colorsThemeSet(@[ |
| 100 | + AAGradientColor.oceanBlueColor, |
| 101 | + AAGradientColor.sanguineColor, |
| 102 | + AAGradientColor.lusciousLimeColor, |
| 103 | + AAGradientColor.purpleLakeColor, |
| 104 | + AAGradientColor.freshPapayaColor, |
| 105 | + AAGradientColor.ultramarineColor, |
| 106 | + AAGradientColor.pinkSugarColor, |
| 107 | + AAGradientColor.lemonDrizzleColor, |
| 108 | + AAGradientColor.victoriaPurpleColor, |
| 109 | + AAGradientColor.springGreensColor, |
| 110 | + AAGradientColor.mysticMauveColor, |
| 111 | + AAGradientColor.reflexSilverColor, |
| 112 | + AAGradientColor.neonGlowColor, |
| 113 | + AAGradientColor.berrySmoothieColor, |
| 114 | + AAGradientColor.newLeafColor, |
| 115 | + AAGradientColor.cottonCandyColor, |
| 116 | + AAGradientColor.pixieDustColor, |
| 117 | + AAGradientColor.fizzyPeachColor, |
| 118 | + AAGradientColor.sweetDreamColor, |
| 119 | + AAGradientColor.firebrickColor, |
| 120 | + AAGradientColor.wroughtIronColor, |
| 121 | + AAGradientColor.deepSeaColor, |
| 122 | + AAGradientColor.coastalBreezeColor, |
| 123 | + AAGradientColor.eveningDelightColor, |
| 124 | + ]) |
| 125 | + |
| 126 | + .seriesSet(@[ |
| 127 | + AASeriesElement.new |
| 128 | + .nameSet(@"ElementOne") |
| 129 | + .zIndexSet(@0) |
| 130 | + .borderRadiusBottomLeftSet((id)@"50%") |
| 131 | + .borderRadiusBottomRightSet((id)@"50%") |
| 132 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:100 minNum:200]) |
| 133 | + .colorByPointSet(@true),//When using automatic point colors pulled from the options.colors collection, this option determines whether the chart should receive one color per series or one color per point. Default Value:false. |
| 134 | + ]); |
| 135 | + |
| 136 | + _gradientColorsArr = aaChartModel.colorsTheme; |
| 137 | + |
| 138 | + AAOptions *aaOptions = aaChartModel.aa_toAAOptions; |
| 139 | + aaOptions.plotOptions.column.groupPadding = @0; |
| 140 | + aaOptions.yAxis.gridLineWidth = @0; |
| 141 | + aaOptions.xAxis |
| 142 | + .crosshairSet(AACrosshair.new |
| 143 | + .colorSet(AAColor.redColor) |
| 144 | + .dashStyleSet(AAChartLineDashStyleTypeLongDashDot) |
| 145 | + .zIndexSet(@5) |
| 146 | + ); |
| 147 | + |
| 148 | + [aaChartView aa_drawChartWithOptions:aaOptions]; |
| 149 | +} |
| 150 | + |
| 151 | + |
| 152 | +- (void)setupChartViewHandler { |
| 153 | + [_aaChartView1 moveOverEventHandler:^(AAChartView *aaChartView, |
| 154 | + AAMoveOverEventMessageModel *message) { |
| 155 | + //默认选中的位置索引 |
| 156 | + NSUInteger defaultSelectedIndex = message.index; |
| 157 | + |
| 158 | + //https://api.highcharts.com/highcharts/chart.events.load |
| 159 | + //https://www.highcharts.com/forum/viewtopic.php?t=36508 |
| 160 | + NSString *jsFunc = ([NSString stringWithFormat:@AAJSFunc(( |
| 161 | + function syncRefreshTooltip() { |
| 162 | + const points = []; |
| 163 | + const chart = aaGlobalChart; |
| 164 | + const series = chart.series; |
| 165 | + const length = series.length; |
| 166 | + |
| 167 | + for (let i = 0; i < length; i++) { |
| 168 | + const pointElement = series[i].data[%ld]; |
| 169 | + pointElement.onMouseOver(); |
| 170 | + points.push(pointElement); |
| 171 | + } |
| 172 | + chart.xAxis[0].drawCrosshair(null, points[0]); |
| 173 | + chart.tooltip.refresh(points); |
| 174 | + } |
| 175 | + syncRefreshTooltip(); |
| 176 | + )), defaultSelectedIndex]); |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + [self.aaChartView2 aa_evaluateJavaScriptStringFunction:jsFunc]; |
| 181 | + }]; |
| 182 | +} |
| 183 | + |
| 184 | +- (NSArray *)generateRandomNumberArrayWithLength:(NSUInteger)length |
| 185 | + randomRange:(NSUInteger)randomRange |
| 186 | + minNum:(NSUInteger)minNum { |
| 187 | + NSMutableArray *randomNumArrA = [NSMutableArray array]; |
| 188 | + for (NSUInteger x = 0; x < length; x++) { |
| 189 | + NSUInteger randomNum = arc4random() % randomRange + minNum; |
| 190 | + [randomNumArrA addObject:@(randomNum)]; |
| 191 | + } |
| 192 | + return randomNumArrA; |
| 193 | +} |
| 194 | + |
| 195 | +//配置第二个 AAChartView |
| 196 | +- (void)setUpTheAAChartViewTwo { |
| 197 | + CGFloat chartViewWidth = self.view.frame.size.width; |
| 198 | + CGFloat screenHeight = self.view.frame.size.height; |
| 199 | + CGRect frame = CGRectMake(0, screenHeight / 2 + 60, chartViewWidth, screenHeight / 2 - 60); |
| 200 | + AAChartView *aaChartView2 = [[AAChartView alloc]initWithFrame:frame]; |
| 201 | + aaChartView2.scrollEnabled = NO; |
| 202 | + [self.view addSubview:aaChartView2]; |
| 203 | + _aaChartView2 = aaChartView2; |
| 204 | + |
| 205 | + AAChartModel *aaChartModel2 = AAChartModel.new |
| 206 | + .chartTypeSet(AAChartTypeAreaspline) |
| 207 | + .markerSymbolStyleSet(AAChartSymbolStyleTypeBorderBlank) |
| 208 | + .markerRadiusSet(@6) |
| 209 | + .stackingSet(AAChartStackingTypeNormal) |
| 210 | + .xAxisCrosshairSet([AACrosshair crosshairWithColor:AAColor.redColor dashStyle:AAChartLineDashStyleTypeDashDot]) |
| 211 | + .legendEnabledSet(false) |
| 212 | + .seriesSet(@[ |
| 213 | + AASeriesElement.new |
| 214 | + .nameSet(@"2018") |
| 215 | + .lineWidthSet(@6) |
| 216 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:100 minNum:200]), |
| 217 | + AASeriesElement.new |
| 218 | + .nameSet(@"2019") |
| 219 | + .lineWidthSet(@6) |
| 220 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:150 minNum:400]), |
| 221 | + AASeriesElement.new |
| 222 | + .nameSet(@"2020") |
| 223 | + .lineWidthSet(@6) |
| 224 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:150 minNum:600]), |
| 225 | + AASeriesElement.new |
| 226 | + .nameSet(@"2018") |
| 227 | + .lineWidthSet(@6) |
| 228 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:100 minNum:200]), |
| 229 | + AASeriesElement.new |
| 230 | + .nameSet(@"2019") |
| 231 | + .lineWidthSet(@6) |
| 232 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:150 minNum:400]), |
| 233 | + AASeriesElement.new |
| 234 | + .nameSet(@"2020") |
| 235 | + .lineWidthSet(@6) |
| 236 | + .dataSet([self generateRandomNumberArrayWithLength:35.0 randomRange:150 minNum:600]), |
| 237 | + ]); |
| 238 | + |
| 239 | + AAOptions *aaOptions2 = aaChartModel2.aa_toAAOptions; |
| 240 | + aaOptions2.plotOptions.column.groupPadding = @0; |
| 241 | + aaOptions2.yAxis.gridLineWidth = @0; |
| 242 | + |
| 243 | + [aaChartView2 aa_drawChartWithOptions:aaOptions2]; |
| 244 | + |
| 245 | +} |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | +@end |
0 commit comments