├── .gitignore ├── BBStockChartView.podspec ├── BBStockChartView ├── Area │ ├── Area.h │ └── Area.m ├── Axis │ ├── AxisX.h │ ├── AxisX.m │ ├── AxisY.h │ └── AxisY.m ├── BBChartUtils.h ├── BBChartUtils.m ├── BBChartView.h ├── BBChartView.m ├── BBStockChart.h ├── BBTheme.h ├── BBTheme.m ├── BaseLayer.h ├── BaseLayer.m └── Series │ ├── BarSeries.h │ ├── BarSeries.m │ ├── LineSeries.h │ ├── LineSeries.m │ ├── Series.h │ ├── Series.m │ ├── StockSeries.h │ └── StockSeries.m ├── BBStockChartViewDemo ├── BBStockChartViewDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── BBStockChartViewDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── BBStockChartViewDemoTests │ ├── BBStockChartViewDemoTests.m │ └── Info.plist ├── Screenshots │ ├── 1.png │ └── v1.1.0.png └── data.json ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | ._* 4 | build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.hmap 18 | *.ipa 19 | *.xcuserstate 20 | .idea 21 | 22 | # CocoaPods 23 | # 24 | # We recommend against adding the Pods directory to your .gitignore. However 25 | # you should judge for yourself, the pros and cons are mentioned at: 26 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 27 | # 28 | # Pods/ 29 | -------------------------------------------------------------------------------- /BBStockChartView.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint BBStockChartView.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "BBStockChartView" 19 | s.version = "1.3.3" 20 | s.summary = "An iOS stock chart library in Objective-C, K-Line." 21 | 22 | s.description = <<-DESC 23 | A stock chart view written in Objective-C, including K-Line 24 | DESC 25 | 26 | s.homepage = "https://github.com/chenxiaoyu3/BBStockChartView" 27 | 28 | 29 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 30 | # 31 | # Licensing your code is important. See http://choosealicense.com for more info. 32 | # CocoaPods will detect a license file if there is a named LICENSE* 33 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 34 | # 35 | 36 | # s.license = "GPLv2" 37 | s.license = { :type => "MIT", :file => "LICENSE.md" } 38 | 39 | 40 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 41 | # 42 | # Specify the authors of the library, with email addresses. Email addresses 43 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 44 | # accepts just a name if you'd rather not provide an email address. 45 | # 46 | # Specify a social_media_url where others can refer to, for example a twitter 47 | # profile URL. 48 | # 49 | 50 | s.author = { "chenxiaoyu" => "chenxiaoyu3@gmail.com" } 51 | # Or just: s.author = "chenxiaoyu" 52 | # s.authors = { "chenxiaoyu" => "chenxiaoyu3@gmail.com" } 53 | # s.social_media_url = "http://twitter.com/chenxiaoyu" 54 | 55 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 56 | # 57 | # If this Pod runs only on iOS or OS X, then specify the platform and 58 | # the deployment target. You can optionally include the target after the platform. 59 | # 60 | 61 | s.platform = :ios 62 | s.platform = :ios, "5.0" 63 | 64 | # When using multiple platforms 65 | # s.ios.deployment_target = "5.0" 66 | # s.osx.deployment_target = "10.7" 67 | 68 | 69 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 70 | # 71 | # Specify the location from where the source should be retrieved. 72 | # Supports git, hg, bzr, svn and HTTP. 73 | # 74 | 75 | s.source = { :git => "https://github.com/chenxiaoyu3/BBStockChartView.git", :tag => "1.3.3" } 76 | 77 | 78 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 79 | # 80 | # CocoaPods is smart about how it includes source code. For source files 81 | # giving a folder will include any h, m, mm, c & cpp files. For header 82 | # files it will include any header in the folder. 83 | # Not including the public_header_files will make all headers public. 84 | # 85 | 86 | s.source_files = "BBStockChartView", "BBStockChartView/**/*" 87 | s.exclude_files = "BBStockChartViewDemo" 88 | 89 | # s.public_header_files = "BBStockChartView/BBStockChart.h" 90 | 91 | 92 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 93 | # 94 | # A list of resources included with the Pod. These are copied into the 95 | # target bundle with a build phase script. Anything else will be cleaned. 96 | # You can preserve files from being cleaned, please don't preserve 97 | # non-essential files like tests, examples and documentation. 98 | # 99 | 100 | # s.resource = "icon.png" 101 | # s.resources = "Resources/*.png" 102 | 103 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 104 | 105 | 106 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 107 | # 108 | # Link your library with frameworks, or libraries. Libraries do not include 109 | # the lib prefix of their name. 110 | # 111 | 112 | # s.framework = "SomeFramework" 113 | s.frameworks = "Foundation", "CoreGraphics", "UIKit" 114 | 115 | # s.library = "iconv" 116 | # s.libraries = "iconv", "xml2" 117 | 118 | 119 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 120 | # 121 | # If your library depends on compiler flags you can set them in the xcconfig hash 122 | # where they will only apply to your library. If you depend on other Podspecs 123 | # you can include multiple dependencies to ensure it works. 124 | 125 | s.requires_arc = true 126 | 127 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 128 | # s.dependency "JSONKit", "~> 1.4" 129 | 130 | end 131 | -------------------------------------------------------------------------------- /BBStockChartView/Area/Area.h: -------------------------------------------------------------------------------- 1 | // 2 | // Area.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BaseLayer.h" 11 | #import "Series.h" 12 | #import "AxisY.h" 13 | #import "AxisX.h" 14 | 15 | @interface Area : BaseLayer 16 | 17 | @property (nonatomic, strong) NSMutableArray* theSeries; 18 | @property (nonatomic, strong) AxisY* leftAxis; 19 | @property (nonatomic, strong) AxisY* rightAxis; 20 | @property (nonatomic, strong) AxisX* bottomAxis; 21 | 22 | //percentage 23 | @property (nonatomic) CGFloat axisYwidth; 24 | @property (nonatomic) CGFloat axisXheight; 25 | -(void) addSeries:(Series*)series; 26 | 27 | -(void) drawAnimated:(BOOL)animated; 28 | -(void) redrawAnimated:(BOOL)animated; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /BBStockChartView/Area/Area.m: -------------------------------------------------------------------------------- 1 | // 2 | // Area.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "Area.h" 10 | 11 | @implementation Area 12 | -(instancetype)init{ 13 | self = [super init]; 14 | if (self) { 15 | _theSeries = [[NSMutableArray alloc] init]; 16 | _leftAxis = [[AxisY alloc] init]; 17 | _rightAxis = [[AxisY alloc] init]; 18 | _bottomAxis = [[AxisX alloc] init]; 19 | 20 | _axisYwidth = 50; 21 | _axisXheight = 30; 22 | [self addSublayer:_leftAxis]; 23 | [self addSublayer:_rightAxis]; 24 | [self addSublayer:_bottomAxis]; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)addSeries:(Series *)series{ 30 | series.position = CGPointZero; 31 | series.anchorPoint = CGPointZero; 32 | series.axisAttached = self.leftAxis; 33 | [self addSublayer:series]; 34 | [self.theSeries addObject:series]; 35 | } 36 | 37 | -(void)prepareForDraw{ 38 | CGFloat height = self.bounds.size.height; 39 | CGFloat width = self.bounds.size.width; 40 | // adjust sublayer's size 41 | 42 | _leftAxis.bounds = CGRectMake(0, 0, _axisYwidth, height - _axisXheight); 43 | _leftAxis.anchorPoint = CGPointZero; 44 | _leftAxis.position = CGPointZero; 45 | 46 | _bottomAxis.bounds = CGRectMake(0, 0, width - _axisYwidth, _axisXheight); 47 | _bottomAxis.anchorPoint = CGPointZero; 48 | _bottomAxis.position = CGPointMake(_axisYwidth, height - _axisXheight); 49 | 50 | NSUInteger maxIdxNum = 0; 51 | for (Series* s in _theSeries) { 52 | s.bounds = CGRectMake(0, 0, width - _axisYwidth, height -_axisXheight); 53 | s.position = CGPointMake( _axisYwidth, 0); 54 | [s prepareForDraw]; 55 | if (s.data.count > maxIdxNum) { 56 | maxIdxNum = s.data.count; 57 | } 58 | } 59 | _bottomAxis.idxNum = maxIdxNum; 60 | 61 | } 62 | 63 | 64 | - (void)drawAnimated:(BOOL)animated{ 65 | 66 | for (Series* s in _theSeries) { 67 | [s drawAnimated:animated]; 68 | } 69 | // 因为在series draw的时候,才会addContainingVal,所以axis的draw必须在series draw后面进行 70 | [_leftAxis drawAnimated:animated]; 71 | [_bottomAxis drawAnimated:animated]; 72 | // [_rightAxis drawAnimated:YES]; 73 | } 74 | - (void)redrawAnimated:(BOOL)animated{ 75 | for (Series* s in _theSeries) { 76 | [s redrawAnimated:animated]; 77 | } 78 | [_leftAxis redrawAnimated:animated]; 79 | [_bottomAxis redrawAnimated:animated]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /BBStockChartView/Axis/AxisX.h: -------------------------------------------------------------------------------- 1 | // 2 | // AxisX.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BaseLayer.h" 11 | 12 | @protocol AxisXLabelProvider 13 | @required 14 | -(NSString*)textForIdx:(NSUInteger)idx; 15 | @end 16 | 17 | @interface AxisX : BaseLayer 18 | 19 | @property (nonatomic) NSUInteger idxNum; 20 | 21 | @property (nonatomic, strong) id labelProvider; 22 | @end 23 | -------------------------------------------------------------------------------- /BBStockChartView/Axis/AxisX.m: -------------------------------------------------------------------------------- 1 | // 2 | // AxisX.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "AxisX.h" 10 | #import "BBTheme.h" 11 | #import "BBChartUtils.h" 12 | 13 | @implementation AxisX 14 | 15 | - (void)drawAnimated:(BOOL)animated{ 16 | CGFloat height = self.bounds.size.height; 17 | CGFloat width = self.bounds.size.width; 18 | CALayer* line = [BaseLayer layerOfLineFrom:CGPointZero to:CGPointMake(width+2, 0) withColor:[BBTheme theme].axisColor andWidth:1]; 19 | line.position = CGPointMake(-2, 1); 20 | line.anchorPoint = CGPointZero; 21 | [self addSublayer:line]; 22 | 23 | CGFloat idxWidth = width / self.idxNum; 24 | NSUInteger maxLabelNum = width / 10; 25 | NSUInteger step = 1; 26 | CGFloat labelWidth = idxWidth; 27 | if (self.idxNum > maxLabelNum) { 28 | step = self.idxNum / maxLabelNum + 1; 29 | labelWidth = width / maxLabelNum; 30 | } 31 | 32 | for(int i = 0; i < self.idxNum; i += 1){ 33 | NSString* text = nil; 34 | if (self.labelProvider) { 35 | text = [self.labelProvider textForIdx:i]; 36 | }else{ 37 | text = [NSString stringWithFormat:@"%d", i+1]; 38 | } 39 | if (text && text.length > 0) { 40 | // NSLog(@"Draw x: %d", i); 41 | CATextLayer* label = [BaseLayer layerOfText:text withFont:@"HelveticaNeue" fontSize:[BBTheme theme].xAxisFontSize andColor:[BBTheme theme].axisColor]; 42 | CGFloat w = [BBChartUtils textBoundsForFont:text andSize:[BBTheme theme].xAxisFontSize text:text].width; 43 | if (i == self.idxNum-1 || idxWidth*i+idxWidth/2+w > width) { 44 | label.alignmentMode = kCAAlignmentRight; 45 | label.bounds = CGRectMake(0, 0, w, height-3); 46 | label.anchorPoint = CGPointMake(1, 0); 47 | }else{ 48 | label.alignmentMode = kCAAlignmentCenter; 49 | label.bounds = CGRectMake(0, 0, w, height-3); 50 | label.anchorPoint = CGPointMake(0.5, 0); 51 | } 52 | label.position = CGPointMake(idxWidth*i + idxWidth /2 , 5); 53 | [self addSublayer:label]; 54 | 55 | 56 | CALayer* dash = [BaseLayer layerOfLineFrom:CGPointMake(idxWidth/2, 0) to:CGPointMake(idxWidth/2, 5) withColor:[BBTheme theme].axisColor andWidth:1]; 57 | dash.anchorPoint = CGPointZero; 58 | dash.position = CGPointMake(idxWidth*i, 1); 59 | [self addSublayer:dash]; 60 | } 61 | } 62 | } 63 | 64 | - (void)redrawAnimated:(BOOL)animated{ 65 | self.sublayers = nil; 66 | [self drawAnimated:animated]; 67 | } 68 | @end 69 | -------------------------------------------------------------------------------- /BBStockChartView/Axis/AxisY.h: -------------------------------------------------------------------------------- 1 | // 2 | // AxisY.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "BaseLayer.h" 12 | 13 | @interface AxisY : BaseLayer 14 | 15 | @property (nonatomic) CGFloat minVal; 16 | @property (nonatomic) CGFloat maxVal; 17 | 18 | @property (nonatomic, readonly) CGFloat designHight; 19 | 20 | // For barSeries, the minValue shouldn't touch the bottom 21 | @property (nonatomic) BOOL touchBottom; 22 | 23 | -(void)addContainingVal:(CGFloat) val; 24 | 25 | -(CGFloat)heighForVal:(CGFloat) val; 26 | -(CGFloat)valForHeigth:(CGFloat) height; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /BBStockChartView/Axis/AxisY.m: -------------------------------------------------------------------------------- 1 | // 2 | // AxisY.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "AxisY.h" 10 | #import 11 | #import "BBTheme.h" 12 | #import "BBChartUtils.h" 13 | 14 | @implementation AxisY 15 | 16 | - (instancetype)init{ 17 | self = [super init]; 18 | if (self) { 19 | self.minVal = FLT_MAX; 20 | self.maxVal = -FLT_MAX; 21 | self.touchBottom = YES; 22 | } 23 | return self; 24 | } 25 | -(void)addContainingVal:(CGFloat)val{ 26 | if (self.minVal > val) { 27 | self.minVal = val; 28 | } 29 | if (self.maxVal < val) { 30 | self.maxVal = val; 31 | } 32 | } 33 | 34 | - (CGFloat)designHight{ 35 | return self.bounds.size.height; 36 | } 37 | 38 | - (void)setTouchBottom:(BOOL)touchBottom{ 39 | if (!_touchBottom) { 40 | return; 41 | } 42 | _touchBottom = touchBottom; 43 | } 44 | - (CGFloat)heighForVal:(CGFloat)val{ 45 | CGFloat low = self.minVal; 46 | CGFloat high = self.maxVal; 47 | 48 | if (!self.touchBottom) { 49 | low -= (high - low) * 0.2; 50 | } 51 | if (high - low <= 0.001) { 52 | return 0; 53 | } 54 | return (val - low) * self.designHight / (high-low) ; 55 | } 56 | 57 | - (CGFloat)valForHeigth:(CGFloat)height{ 58 | CGFloat low = self.minVal; 59 | CGFloat high = self.maxVal; 60 | 61 | if (!self.touchBottom) { 62 | low -= (high - low) * 0.2; 63 | } 64 | return height * (high-low) / self.designHight + low; 65 | } 66 | 67 | //-(CATextLayer*)textLabel:(NSString*)text{ 68 | // CATextLayer* ret = [[CATextLayer alloc] init]; 69 | // ret.fontSize = 13; 70 | // ret.string = text; 71 | // ret.foregroundColor = [UIColor redColor].CGColor; 72 | // return ret; 73 | //} 74 | -(CGSize)sizeOfText:(NSString*) text andSize:(CGFloat)size{ 75 | 76 | CGSize textSize = [BBChartUtils textBoundsForFont:[UIFont systemFontOfSize:size].familyName andSize:size text:text]; 77 | return textSize; 78 | } 79 | 80 | -(void)drawAnimated:(BOOL)animated{ 81 | CGFloat width = self.bounds.size.width; 82 | CGFloat height = self.bounds.size.height; 83 | CALayer* line = [BaseLayer layerOfLineFrom:CGPointZero to:CGPointMake(0, self.designHight+1) withColor:[BBTheme theme].axisColor andWidth:1.5]; 84 | line.position = CGPointMake(self.bounds.size.width-2, 0); 85 | [self addSublayer:line]; 86 | 87 | CGFloat labelGap = 20; 88 | 89 | NSUInteger cnt = self.bounds.size.height / labelGap; 90 | CGFloat labelHei = [self sizeOfText:@"abc" andSize:[BBTheme theme].yAxisFontSize].height; 91 | 92 | for (int i = 1; i < cnt; ++i) { 93 | CGFloat curHei = i * labelGap; 94 | CALayer* dash = [BaseLayer layerOfLineFrom:CGPointMake(self.bounds.size.width-1.5-5, curHei) to:CGPointMake(self.bounds.size.width-2, curHei) withColor:[BBTheme theme].axisColor andWidth:1]; 95 | 96 | CGFloat val = [self valForHeigth:height-curHei]; 97 | NSString* lab = [NSString stringWithFormat:@"%.3f", val]; 98 | if (val > 1000) { 99 | lab = [NSString stringWithFormat:@"%.1f", val]; 100 | } 101 | CATextLayer* t = [BaseLayer layerOfText:lab withFont:@"Helvetica" fontSize:[BBTheme theme].yAxisFontSize andColor:[BBTheme theme].axisColor]; 102 | t.alignmentMode = kCAAlignmentRight; 103 | 104 | // NSLog(@"mark val:%.1f H:%f", [self valForHeigth:curHei], curHei); 105 | if (i == 0) { 106 | t.anchorPoint = CGPointZero; 107 | }else{ 108 | t.anchorPoint = CGPointMake(0, 0.5); 109 | } 110 | 111 | t.position = CGPointMake(0, curHei); 112 | t.bounds = CGRectMake(0, 0, width-12, labelHei); 113 | 114 | [self addSublayer:t]; 115 | [self addSublayer:dash]; 116 | } 117 | 118 | } 119 | 120 | - (void)redrawAnimated:(BOOL)animated{ 121 | self.sublayers = nil; 122 | [self drawAnimated:animated]; 123 | } 124 | @end 125 | -------------------------------------------------------------------------------- /BBStockChartView/BBChartUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBChartUtils.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface BBChartUtils : NSObject 13 | 14 | +(CGFloat) nearestRound:(CGFloat)val; 15 | 16 | +(NSUInteger) digitsNumBeforeDot:(CGFloat)val; 17 | 18 | +(CGSize) textBoundsForFont:(NSString*)font andSize:(CGFloat)size text:(NSString*)text; 19 | @end 20 | -------------------------------------------------------------------------------- /BBStockChartView/BBChartUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBChartUtils.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "BBChartUtils.h" 10 | 11 | @implementation BBChartUtils 12 | 13 | + (NSUInteger)digitsNumBeforeDot:(CGFloat)val{ 14 | NSUInteger ret = 0; 15 | while (val >= 1) { 16 | val /= 10; 17 | ++ret; 18 | } 19 | return ret; 20 | } 21 | //TODO: Y坐标轴,尽量显示整数 22 | + (CGFloat)nearestRound:(CGFloat)val{ 23 | if (val >= 1 ) { 24 | 25 | } 26 | return 0; 27 | } 28 | 29 | + (CGSize)textBoundsForFont:(NSString *)font andSize:(CGFloat)size text:(NSString *)text{ 30 | CGFloat fontSize = size; 31 | CGRect r = [text boundingRectWithSize:CGSizeMake(200, 0) 32 | options:NSStringDrawingUsesLineFragmentOrigin 33 | attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} 34 | context:nil]; 35 | return r.size; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /BBStockChartView/BBChartView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBChartView.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "Area.h" 11 | @interface BBChartView : UIView{ 12 | 13 | } 14 | 15 | @property (nonatomic) CGFloat scaleFloor; 16 | 17 | //when pinch the view, scale it in-time, not after. Default is NO. 18 | @property (nonatomic) BOOL realTimeScale; 19 | 20 | -(void)setHeighRatio:(CGFloat)heightRatio forArea:(Area*)area; 21 | -(void)addArea:(Area *)area; 22 | 23 | -(void)drawAnimated:(BOOL)animated; 24 | -(void)reset; 25 | 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /BBStockChartView/BBChartView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBChartView.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "BBChartView.h" 10 | #import "BarSeries.h" 11 | #import "StockSeries.h" 12 | #import "BBTheme.h" 13 | 14 | @interface BBChartView(){ 15 | 16 | float _currentScale; 17 | float _currentX; 18 | 19 | NSMutableArray* _areas; 20 | NSMutableArray* _areaHeights; 21 | 22 | // content chart view 23 | UIView* _chartView; 24 | UIView* _toastView; 25 | UILabel* _toastLabel; 26 | 27 | } 28 | 29 | - (void) redraw; 30 | @end 31 | 32 | @implementation BBChartView 33 | 34 | - (instancetype)init{ 35 | self = [super init]; 36 | if (self) { 37 | [self _init]; 38 | } 39 | return self; 40 | } 41 | 42 | 43 | - (instancetype)initWithFrame:(CGRect)frame{ 44 | self = [super initWithFrame:frame]; 45 | if (self) { 46 | [self _init]; 47 | } 48 | return self; 49 | } 50 | 51 | - (void)_init{ 52 | _areas = [[NSMutableArray alloc] init]; 53 | _areaHeights = [[NSMutableArray alloc] init]; 54 | _chartView = [[UIView alloc] initWithFrame:self.frame]; 55 | self.userInteractionEnabled = YES; 56 | self.multipleTouchEnabled = YES; 57 | self.clipsToBounds = YES; 58 | [self addSubview:_chartView]; 59 | [self _initToastView]; 60 | 61 | UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; 62 | [self addGestureRecognizer:panGesture]; 63 | UIPinchGestureRecognizer* pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; 64 | [self addGestureRecognizer:pinchGesture]; 65 | 66 | _scaleFloor = 2; 67 | _currentScale = 1; 68 | _currentX = 0; 69 | } 70 | 71 | - (void)setScaleFloor:(CGFloat)scaleFloor{ 72 | if (scaleFloor < 1) { 73 | _scaleFloor = 1; 74 | }else{ 75 | _scaleFloor = scaleFloor; 76 | } 77 | } 78 | 79 | - (void)_initToastView{ 80 | _toastView = [[UIView alloc] init]; 81 | _toastLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 61.8)]; 82 | UILabel* label = _toastLabel; 83 | label.textAlignment = NSTextAlignmentCenter; 84 | label.text = @"x1.3"; 85 | label.font = [UIFont systemFontOfSize:24]; 86 | label.textColor = [UIColor whiteColor]; 87 | [_toastView addSubview:label]; 88 | _toastView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4]; 89 | _toastView.layer.cornerRadius = 6; 90 | _toastView.layer.masksToBounds = YES; 91 | 92 | } 93 | 94 | - (void)setHeighRatio:(CGFloat)heightRatio forArea:(Area *)area{ 95 | if (_areas.count < 2) { 96 | return; 97 | } 98 | CGFloat thisHeight = self.bounds.size.height * heightRatio; 99 | CGFloat otherHeight = (self.bounds.size.height - thisHeight) / (_areas.count-1); 100 | [_areas enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 101 | Area* cur = obj; 102 | if (cur == area) { 103 | _areaHeights[idx] = [NSNumber numberWithFloat:thisHeight]; 104 | }else{ 105 | _areaHeights[idx] = [NSNumber numberWithFloat:otherHeight]; 106 | } 107 | }]; 108 | } 109 | - (void)addArea:(Area *)area{ 110 | [_areas addObject:area]; 111 | 112 | [_chartView.layer addSublayer:area]; 113 | 114 | [_areaHeights removeAllObjects]; 115 | for (int i = 0; i < _areas.count; ++i) { 116 | [_areaHeights addObject:[NSNumber numberWithFloat:1.0f/_areas.count*self.bounds.size.height]]; 117 | } 118 | 119 | 120 | } 121 | 122 | - (void)prepareForDraw{ 123 | _toastView.frame = CGRectMake(self.frame.size.width / 2 - 50, 0, 100, 61.8); 124 | _chartView.frame = CGRectMake(0, 0, self.frame.size.width * _currentScale, self.frame.size.height); 125 | CGFloat width = _chartView.layer.bounds.size.width; 126 | // CGFloat height = self.layer.bounds.size.height; 127 | 128 | CGFloat curY = 0; 129 | for (int i = 0; i < _areas.count; ++i) { 130 | Area* area = _areas[i]; 131 | CGFloat curHeight = [(NSNumber*)_areaHeights[i] floatValue]; 132 | area.bounds = CGRectMake(0, 0, width, curHeight); 133 | area.position = CGPointMake(0, curY); 134 | area.anchorPoint = CGPointZero; 135 | [area prepareForDraw]; 136 | curY += curHeight; 137 | } 138 | 139 | } 140 | - (void)drawAnimated:(BOOL)animated{ 141 | self.backgroundColor = [BBTheme theme].backgroundColor; 142 | [self prepareForDraw]; 143 | for (Area* a in _areas) { 144 | [a drawAnimated:animated]; 145 | } 146 | // self.layer.borderWidth = 1; 147 | // self.layer.borderColor = [BBTheme defTheme].borderColor.CGColor; 148 | } 149 | - (void)redraw{ 150 | self.backgroundColor = [BBTheme theme].backgroundColor; 151 | [self prepareForDraw]; 152 | for (Area* a in _areas) { 153 | [a redrawAnimated:NO]; 154 | } 155 | } 156 | 157 | - (void)reset{ 158 | for (Area* area in _areas) { 159 | [area removeFromSuperlayer]; 160 | } 161 | [_areas removeAllObjects]; 162 | [_areaHeights removeAllObjects]; 163 | } 164 | 165 | #pragma mark panGesture 166 | - (void) scaleWith:(float)ratio{ 167 | CGRect newFrame = CGRectMake(_chartView.frame.origin.x, _chartView.frame.origin.y, self.frame.size.width, self.frame.size.height); 168 | newFrame.size.width = newFrame.size.width * ratio; 169 | _chartView.frame = newFrame; 170 | [self redraw]; 171 | } 172 | - (void) properPosition{ 173 | CGFloat newX = _chartView.frame.origin.x; 174 | if (newX > 0) { 175 | newX = 0; 176 | } 177 | if (newX + _chartView.frame.size.width < self.frame.size.width) { 178 | newX = self.frame.size.width - _chartView.frame.size.width; 179 | } 180 | if (newX != _chartView.frame.origin.x) { 181 | [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 182 | _chartView.frame = CGRectMake(newX, 0, _chartView.frame.size.width, _chartView.frame.size.height); 183 | } completion: nil]; 184 | } 185 | 186 | 187 | } 188 | // TODO: the axisX should be fixed when dragging the view 189 | - (void) handlePanGesture:(UIPanGestureRecognizer* )recognizer{ 190 | CGPoint trans = [recognizer translationInView:_chartView]; 191 | CGFloat newX = _currentX + trans.x; 192 | if (newX > 0) { 193 | newX = 0; 194 | } 195 | if (newX + _chartView.frame.size.width < self.frame.size.width) { 196 | newX = self.frame.size.width - _chartView.frame.size.width; 197 | } 198 | // NSLog(@"newX %f", trans.x); 199 | if (recognizer.state == UIGestureRecognizerStateEnded) { 200 | _currentX = newX; 201 | } 202 | // make the drag smoother 203 | [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 204 | _chartView.frame = CGRectMake(newX, 0, _chartView.frame.size.width, _chartView.frame.size.height); 205 | } completion: ^(BOOL finished){ 206 | 207 | }]; 208 | } 209 | - (void) handlePinchGesture:(UIPinchGestureRecognizer* )recognizer{ 210 | if (recognizer.state == UIGestureRecognizerStateBegan) { 211 | [self addSubview:_toastView]; 212 | return; 213 | } 214 | float s = ((int)(recognizer.scale * 10)) / 10.0; 215 | float scale = s - 1 + _currentScale; 216 | if (scale > _scaleFloor) { 217 | scale = _scaleFloor; 218 | } 219 | if (scale < 1) { 220 | scale = 1; 221 | } 222 | if (_realTimeScale) { 223 | // TODO: redraw all the sublayers make the real-time scale stuck, needs to be fixed. 224 | [self scaleWith:scale]; 225 | } 226 | 227 | if (recognizer.state == UIGestureRecognizerStateEnded) { 228 | [_toastView removeFromSuperview]; 229 | _currentScale = scale; 230 | [self scaleWith:scale]; 231 | [self properPosition]; 232 | return; 233 | } 234 | _toastLabel.text = [NSString stringWithFormat:@"x %.1f", scale]; 235 | } 236 | 237 | @end 238 | -------------------------------------------------------------------------------- /BBStockChartView/BBStockChart.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBStockChart.h 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #ifndef BBStockChartViewDemo_BBStockChart_h 10 | #define BBStockChartViewDemo_BBStockChart_h 11 | 12 | #import "Area.h" 13 | #import "AxisX.h" 14 | #import "AxisY.h" 15 | #import "BaseLayer.h" 16 | #import "BBChartUtils.h" 17 | #import "BBTheme.h" 18 | #import "BarSeries.h" 19 | #import "StockSeries.h" 20 | #import "LineSeries.h" 21 | 22 | #import "BBChartView.h" 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /BBStockChartView/BBTheme.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBTheme.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/12. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | #define UIColorFromHex(hex) \ 14 | [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 \ 15 | green:((float)((hex & 0x00FF00) >> 8)) / 255.0 \ 16 | blue:((float)((hex & 0x0000FF) )) / 255.0 \ 17 | alpha:1.0] 18 | 19 | 20 | @interface BBTheme : UIColor 21 | 22 | @property (nonatomic) UIColor* riseColor; 23 | @property (nonatomic) UIColor* fallColor; 24 | 25 | @property (nonatomic) UIColor* barFillColor; 26 | @property (nonatomic) UIColor* barBorderColor; 27 | 28 | @property (nonatomic) CGFloat xAxisFontSize; 29 | @property (nonatomic) CGFloat yAxisFontSize; 30 | @property (nonatomic) UIColor* axisColor; 31 | 32 | @property (nonatomic) UIColor* backgroundColor; 33 | @property (nonatomic) UIColor* borderColor; 34 | 35 | @property (nonatomic) UIColor* defTextColor; 36 | @property (nonatomic) UIColor* defLineColor; 37 | @property (nonatomic) float defLineWidth; 38 | +(BBTheme*) theme; 39 | @end 40 | -------------------------------------------------------------------------------- /BBStockChartView/BBTheme.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBTheme.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/12. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "BBTheme.h" 10 | 11 | BBTheme* _defTheme = nil; 12 | @implementation BBTheme 13 | 14 | - (instancetype)init{ 15 | self = [super init]; 16 | if (self) { 17 | } 18 | return self; 19 | } 20 | 21 | +(BBTheme *)theme{ 22 | if (!_defTheme) { 23 | _defTheme = [[BBTheme alloc] init]; 24 | _defTheme.riseColor = [UIColor greenColor]; 25 | _defTheme.fallColor = [UIColor redColor]; 26 | _defTheme.barFillColor = [UIColor greenColor]; 27 | _defTheme.barBorderColor = [UIColor clearColor]; 28 | _defTheme.xAxisFontSize = 10; 29 | _defTheme.yAxisFontSize = 10; 30 | _defTheme.backgroundColor = [UIColor blackColor]; 31 | _defTheme.axisColor = [UIColor whiteColor]; 32 | _defTheme.borderColor = [UIColor grayColor]; 33 | _defTheme.defTextColor = [UIColor whiteColor]; 34 | _defTheme.defLineColor = [UIColor whiteColor]; 35 | _defTheme.defLineWidth = 1; 36 | } 37 | return _defTheme; 38 | } 39 | @end 40 | -------------------------------------------------------------------------------- /BBStockChartView/BaseLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLayer.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/6. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface BaseLayer : CALayer 13 | 14 | //根据自己的bound.size,调整相关 sublayer的bounds, 并调用子layer的同意函数 15 | 16 | - (void)prepareForDraw; 17 | - (void)drawAnimated:(BOOL)animated; 18 | - (void)redrawAnimated:(BOOL)animated; 19 | 20 | + (CALayer*) layerOfLineFrom:(CGPoint)from to:(CGPoint)to withColor:(UIColor*)color andWidth:(CGFloat)width; 21 | 22 | + (CATextLayer *)layerOfText:(NSString *)text withFont:(NSString*)font fontSize:(CGFloat)fontSize andColor:(UIColor *)color; 23 | @end 24 | -------------------------------------------------------------------------------- /BBStockChartView/BaseLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLayer.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/6. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "BaseLayer.h" 10 | #import 11 | 12 | @implementation BaseLayer 13 | 14 | -(void)drawAnimated:(BOOL)animated{ 15 | 16 | } 17 | - (void)redrawAnimated:(BOOL)animated{ 18 | 19 | } 20 | -(void)prepareForDraw{ 21 | 22 | } 23 | 24 | + (CALayer *)layerOfLineFrom:(CGPoint)from to:(CGPoint)to withColor:(UIColor*)color andWidth:(CGFloat)width{ 25 | CAShapeLayer *line = [CAShapeLayer layer]; 26 | UIBezierPath *linePath = [UIBezierPath bezierPath]; 27 | [linePath moveToPoint: from]; 28 | [linePath addLineToPoint:to]; 29 | line.path = linePath.CGPath; 30 | line.fillColor = nil; 31 | line.opacity = 1.0; 32 | line.strokeColor = color.CGColor; 33 | line.lineWidth = width; 34 | return line; 35 | } 36 | // TODO: when line series is thick, their joint part would leave a small black space, which should be filled 37 | //+ (CALayer *)layerOfConcatLineFrom:(CGPoint)from to:(CGPoint)to withColor:(UIColor*)color andWidth:(CGFloat)width{ 38 | // CAShapeLayer *line = [CAShapeLayer layer]; 39 | // UIBezierPath *linePath = [UIBezierPath bezierPath]; 40 | // [linePath moveToPoint: from]; 41 | // [linePath addLineToPoint:to]; 42 | // line.path = linePath.CGPath; 43 | // line.fillColor = nil; 44 | // line.opacity = 1.0; 45 | // line.strokeColor = color.CGColor; 46 | // line.lineWidth = width; 47 | // return line; 48 | //} 49 | 50 | 51 | + (CATextLayer *)layerOfText:(NSString *)text withFont:(NSString*)font fontSize:(CGFloat)fontSize andColor:(UIColor *)color{ 52 | // UIFont* f = [UIFont fontWithName:font size:fontSize]; 53 | CATextLayer *ret = [[CATextLayer alloc] init]; 54 | ret.string = text; 55 | ret.font = (__bridge CFTypeRef)(font); 56 | ret.fontSize = fontSize; 57 | ret.foregroundColor = color.CGColor; 58 | ret.contentsScale = [UIScreen mainScreen].scale; 59 | return ret; 60 | } 61 | @end 62 | -------------------------------------------------------------------------------- /BBStockChartView/Series/BarSeries.h: -------------------------------------------------------------------------------- 1 | // 2 | // BarSeries.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "Series.h" 10 | 11 | @interface BarSeries : Series 12 | 13 | 14 | 15 | -(void) addPoint:(float)p; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BBStockChartView/Series/BarSeries.m: -------------------------------------------------------------------------------- 1 | // 2 | // BarSeries.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "BarSeries.h" 10 | #import "BBTheme.h" 11 | 12 | @implementation BarSeries 13 | 14 | -(instancetype)init{ 15 | self = [super init]; 16 | if (self) { 17 | 18 | } 19 | return self; 20 | } 21 | - (void)addPoint:(float)p{ 22 | [super.data addObject:[NSNumber numberWithFloat:p]]; 23 | } 24 | 25 | - (void)drawPoint:(NSUInteger)idx animated:(BOOL)animated{ 26 | if (idx >= self.data.count) { 27 | return; 28 | } 29 | CALayer* l = [[CALayer alloc] init]; 30 | l.backgroundColor = [BBTheme theme].barFillColor.CGColor; 31 | l.borderColor = [BBTheme theme].barBorderColor.CGColor; 32 | l.borderWidth = 1; 33 | l.anchorPoint = CGPointMake(0, 1); 34 | CGFloat h =[self.axisAttached heighForVal:((NSNumber*)self.data[idx]).floatValue]; 35 | // NSLog(@"draw val:%.1f atH:%f",((NSNumber*)self.data[idx]).floatValue, h); 36 | l.bounds = CGRectMake(0, 0, self.pointWidth-2, h); 37 | l.position = CGPointMake(idx * self.pointWidth, self.bounds.size.height); 38 | [self addSublayer:l]; 39 | 40 | if (animated) { 41 | CABasicAnimation* ani = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; 42 | ani.fromValue = [NSNumber numberWithFloat:0]; 43 | ani.toValue = [NSNumber numberWithFloat:1.0]; 44 | ani.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; 45 | ani.duration = 1; 46 | [l addAnimation:ani forKey:nil]; 47 | 48 | } 49 | // NSLog(@"Bar draw point:%d", idx); 50 | 51 | } 52 | 53 | - (void)prepareForDraw{ 54 | self.axisAttached.touchBottom = NO; 55 | for (NSNumber* n in self.data) { 56 | [self.axisAttached addContainingVal:n.floatValue]; 57 | } 58 | 59 | } 60 | 61 | //- (void)drawAnimated:(BOOL)animated{ 62 | // 63 | // for (int i = 0; i < self.data.count; ++i) { 64 | // [self drawPoint:i animated:animated]; 65 | // } 66 | //} 67 | // 68 | //- (void)redrawAnimated:(BOOL)animated{ 69 | // self.sublayers = nil; 70 | // [self drawAnimated:animated]; 71 | //} 72 | 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BBStockChartView/Series/LineSeries.h: -------------------------------------------------------------------------------- 1 | // 2 | // LineSeries.h 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/5/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "Series.h" 10 | 11 | @interface LineSeries : Series 12 | 13 | @property (nonatomic, strong) UIColor* color; 14 | @property (nonatomic) float width; 15 | @end 16 | -------------------------------------------------------------------------------- /BBStockChartView/Series/LineSeries.m: -------------------------------------------------------------------------------- 1 | // 2 | // LineSeries.m 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/5/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "LineSeries.h" 10 | #import "BBTheme.h" 11 | @implementation LineSeries 12 | 13 | -(instancetype)init{ 14 | self = [super init]; 15 | if (self) { 16 | self.width = [BBTheme theme].defLineWidth; 17 | self.color = [BBTheme theme].defLineColor; 18 | } 19 | return self; 20 | } 21 | 22 | 23 | - (void)addPoint:(float)p{ 24 | [super.data addObject:[NSNumber numberWithFloat:p]]; 25 | } 26 | 27 | - (void)drawPoint:(NSUInteger)idx animated:(BOOL)animated{ 28 | if (idx == 0 || idx >= self.data.count) { 29 | return; 30 | } 31 | CGFloat height = self.bounds.size.height; 32 | float y1 = height - [self.axisAttached heighForVal:((NSNumber*)self.data[idx-1]).floatValue]; 33 | float y2 = height - [self.axisAttached heighForVal:((NSNumber*)self.data[idx]).floatValue]; 34 | CALayer* line = [BaseLayer layerOfLineFrom:CGPointMake((idx-1)*self.pointWidth, y1) to:CGPointMake(idx*self.pointWidth, y2) withColor:self.color andWidth:self.width]; 35 | 36 | 37 | [self addSublayer:line]; 38 | } 39 | 40 | - (void)prepareForDraw{ 41 | self.axisAttached.touchBottom = YES; 42 | for (NSNumber* n in self.data) { 43 | [self.axisAttached addContainingVal:n.floatValue]; 44 | } 45 | } 46 | @end 47 | -------------------------------------------------------------------------------- /BBStockChartView/Series/Series.h: -------------------------------------------------------------------------------- 1 | // 2 | // Series.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "AxisY.h" 12 | #import "BaseLayer.h" 13 | 14 | @interface Series : BaseLayer 15 | 16 | 17 | @property (nonatomic, strong) NSMutableArray* data; 18 | 19 | @property (nonatomic, readonly) float pointWidth; 20 | @property (nonatomic, weak) AxisY* axisAttached; 21 | 22 | 23 | // 24 | - (void)drawPoint:(NSUInteger)idx animated:(BOOL)animated; 25 | 26 | - (void)drawAnimated:(BOOL)animated; 27 | - (void)redrawAnimated:(BOOL)animated; 28 | 29 | - (void)addPoint:(float)p; 30 | @end 31 | -------------------------------------------------------------------------------- /BBStockChartView/Series/Series.m: -------------------------------------------------------------------------------- 1 | // 2 | // Series.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/5. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "Series.h" 10 | 11 | @implementation Series 12 | 13 | - (instancetype)init{ 14 | self = [super init]; 15 | if (self) { 16 | _data = [[NSMutableArray alloc] init]; 17 | } 18 | return self; 19 | } 20 | -(void)drawPoint:(NSUInteger)idx animated:(BOOL)animated{ 21 | 22 | } 23 | 24 | 25 | - (void)drawAnimated:(BOOL)animated{ 26 | for (int i = 0; i < self.data.count; ++i) { 27 | [self drawPoint:i animated:animated]; 28 | } 29 | } 30 | - (void)redrawAnimated:(BOOL)animated{ 31 | self.sublayers = nil; 32 | [self drawAnimated:animated]; 33 | } 34 | 35 | -(float)pointWidth{ 36 | CGFloat w = self.bounds.size.width; 37 | if ( _data.count == 0) { 38 | return w; 39 | } 40 | return w / _data.count; 41 | 42 | } 43 | 44 | - (void)addPoint:(float)p{ 45 | 46 | } 47 | @end 48 | -------------------------------------------------------------------------------- /BBStockChartView/Series/StockSeries.h: -------------------------------------------------------------------------------- 1 | // 2 | // StockSeries.h 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "Series.h" 10 | 11 | @interface StockSeriesPoint : NSObject 12 | 13 | @property (nonatomic) CGFloat open, close, low, high; 14 | 15 | @end 16 | 17 | 18 | @interface StockSeries : Series 19 | 20 | -(void) addPointOpen:(CGFloat)o close:(CGFloat)c low:(CGFloat)l high:(CGFloat)h; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /BBStockChartView/Series/StockSeries.m: -------------------------------------------------------------------------------- 1 | // 2 | // StockSeries.m 3 | // BBChart 4 | // 5 | // Created by ChenXiaoyu on 15/1/8. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "StockSeries.h" 10 | #import "BBTheme.h" 11 | 12 | @implementation StockSeriesPoint 13 | 14 | @end 15 | @implementation StockSeries 16 | 17 | - (void)addPointOpen:(CGFloat)o close:(CGFloat)c low:(CGFloat)l high:(CGFloat)h{ 18 | StockSeriesPoint * p = [[StockSeriesPoint alloc] init]; 19 | p.open = o; 20 | p.close = c; 21 | p.high = h; 22 | p.low = l; 23 | [self.data addObject:p]; 24 | } 25 | 26 | 27 | - (void)prepareForDraw{ 28 | self.axisAttached.touchBottom = YES; 29 | for (StockSeriesPoint* n in self.data) { 30 | [self.axisAttached addContainingVal:n.high]; 31 | [self.axisAttached addContainingVal:n.low]; 32 | } 33 | 34 | } 35 | 36 | - (void)drawPoint:(NSUInteger)idx animated:(BOOL)animated{ 37 | if (idx >= self.data.count) { 38 | return; 39 | } 40 | StockSeriesPoint* point = (StockSeriesPoint*)(self.data[idx]); 41 | UIColor* color = nil; 42 | if (idx == 0) { 43 | color = [BBTheme theme].riseColor; 44 | }else{ 45 | StockSeriesPoint* prePoint = (StockSeriesPoint*)(self.data[idx-1]); 46 | if (prePoint.open >= point.open) { 47 | color = [BBTheme theme].riseColor; 48 | }else{ 49 | color = [BBTheme theme].fallColor; 50 | } 51 | } 52 | CGFloat height = self.bounds.size.height; 53 | // CGFloat width = self.bounds.size.width; 54 | 55 | 56 | CGFloat x = idx * self.pointWidth + self.pointWidth / 2; 57 | CGFloat y1 = height - [self.axisAttached heighForVal:point.high]; 58 | CGFloat y2 = height - [self.axisAttached heighForVal:point.low]; 59 | 60 | CALayer* lh = [BaseLayer layerOfLineFrom:CGPointZero to:CGPointMake(0, y1-y2+1) withColor:color andWidth:1]; 61 | lh.position = CGPointMake(x, y2); 62 | 63 | if (point.open > point.close) { 64 | y1 = height - [self.axisAttached heighForVal:point.open]; 65 | y2 = height - [self.axisAttached heighForVal:point.close]; 66 | }else{ 67 | y1 = height - [self.axisAttached heighForVal:point.close]; 68 | y2 = height - [self.axisAttached heighForVal:point.open]; 69 | } 70 | 71 | CGFloat ocWidth = 8; 72 | if (self.pointWidth <= ocWidth+2) { 73 | ocWidth = self.pointWidth - 2; 74 | } 75 | CALayer* oc = [BaseLayer layerOfLineFrom:CGPointZero to:CGPointMake(0, y1-y2+1) withColor:color andWidth:ocWidth]; 76 | oc.position = CGPointMake(x, y2); 77 | 78 | // NSLog(@"StockPoint val:%.1f, height:%.1f", point.open, y1); 79 | [self addSublayer:oc]; 80 | [self addSublayer:lh]; 81 | 82 | if (animated) { 83 | CABasicAnimation* ani = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; 84 | ani.fromValue = [NSNumber numberWithFloat:0]; 85 | ani.toValue = [NSNumber numberWithFloat:1.0]; 86 | ani.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; 87 | ani.duration = 1; 88 | 89 | [oc addAnimation:ani forKey:nil]; 90 | [lh addAnimation:ani forKey:nil]; 91 | 92 | } 93 | 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FF31001E1AC3FF570085C822 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FF31001D1AC3FF570085C822 /* main.m */; }; 11 | FF3100211AC3FF570085C822 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100201AC3FF570085C822 /* AppDelegate.m */; }; 12 | FF3100241AC3FF570085C822 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100231AC3FF570085C822 /* ViewController.m */; }; 13 | FF3100271AC3FF570085C822 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FF3100251AC3FF570085C822 /* Main.storyboard */; }; 14 | FF3100291AC3FF570085C822 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FF3100281AC3FF570085C822 /* Images.xcassets */; }; 15 | FF31002C1AC3FF570085C822 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = FF31002A1AC3FF570085C822 /* LaunchScreen.xib */; }; 16 | FF3100381AC3FF570085C822 /* BBStockChartViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100371AC3FF570085C822 /* BBStockChartViewDemoTests.m */; }; 17 | FF3100591AC3FF740085C822 /* Area.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100441AC3FF740085C822 /* Area.m */; }; 18 | FF31005A1AC3FF740085C822 /* AxisX.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100471AC3FF740085C822 /* AxisX.m */; }; 19 | FF31005B1AC3FF740085C822 /* AxisY.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100491AC3FF740085C822 /* AxisY.m */; }; 20 | FF31005C1AC3FF740085C822 /* BaseLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = FF31004B1AC3FF740085C822 /* BaseLayer.m */; }; 21 | FF31005D1AC3FF740085C822 /* BBChartUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = FF31004D1AC3FF740085C822 /* BBChartUtils.m */; }; 22 | FF31005E1AC3FF740085C822 /* BBChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = FF31004F1AC3FF740085C822 /* BBChartView.m */; }; 23 | FF31005F1AC3FF740085C822 /* BBTheme.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100511AC3FF740085C822 /* BBTheme.m */; }; 24 | FF3100601AC3FF740085C822 /* BarSeries.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100541AC3FF740085C822 /* BarSeries.m */; }; 25 | FF3100611AC3FF740085C822 /* Series.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100561AC3FF740085C822 /* Series.m */; }; 26 | FF3100621AC3FF740085C822 /* StockSeries.m in Sources */ = {isa = PBXBuildFile; fileRef = FF3100581AC3FF740085C822 /* StockSeries.m */; }; 27 | FF3100671AC4063A0085C822 /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = FF3100661AC4063A0085C822 /* data.json */; }; 28 | FF6FB8761B14895E006F33BA /* LineSeries.m in Sources */ = {isa = PBXBuildFile; fileRef = FF6FB8751B14895E006F33BA /* LineSeries.m */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXContainerItemProxy section */ 32 | FF3100321AC3FF570085C822 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = FF3100101AC3FF560085C822 /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = FF3100171AC3FF560085C822; 37 | remoteInfo = BBStockChartViewDemo; 38 | }; 39 | /* End PBXContainerItemProxy section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | FF3100181AC3FF560085C822 /* BBStockChartViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BBStockChartViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | FF31001C1AC3FF560085C822 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | FF31001D1AC3FF570085C822 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 45 | FF31001F1AC3FF570085C822 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 46 | FF3100201AC3FF570085C822 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 47 | FF3100221AC3FF570085C822 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 48 | FF3100231AC3FF570085C822 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 49 | FF3100261AC3FF570085C822 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 50 | FF3100281AC3FF570085C822 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 51 | FF31002B1AC3FF570085C822 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 52 | FF3100311AC3FF570085C822 /* BBStockChartViewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BBStockChartViewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | FF3100361AC3FF570085C822 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | FF3100371AC3FF570085C822 /* BBStockChartViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BBStockChartViewDemoTests.m; sourceTree = ""; }; 55 | FF3100431AC3FF740085C822 /* Area.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Area.h; path = Area/Area.h; sourceTree = ""; }; 56 | FF3100441AC3FF740085C822 /* Area.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Area.m; path = Area/Area.m; sourceTree = ""; }; 57 | FF3100461AC3FF740085C822 /* AxisX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisX.h; sourceTree = ""; }; 58 | FF3100471AC3FF740085C822 /* AxisX.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AxisX.m; sourceTree = ""; }; 59 | FF3100481AC3FF740085C822 /* AxisY.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisY.h; sourceTree = ""; }; 60 | FF3100491AC3FF740085C822 /* AxisY.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AxisY.m; sourceTree = ""; }; 61 | FF31004A1AC3FF740085C822 /* BaseLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseLayer.h; sourceTree = ""; }; 62 | FF31004B1AC3FF740085C822 /* BaseLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseLayer.m; sourceTree = ""; }; 63 | FF31004C1AC3FF740085C822 /* BBChartUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBChartUtils.h; sourceTree = ""; }; 64 | FF31004D1AC3FF740085C822 /* BBChartUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBChartUtils.m; sourceTree = ""; }; 65 | FF31004E1AC3FF740085C822 /* BBChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBChartView.h; sourceTree = ""; }; 66 | FF31004F1AC3FF740085C822 /* BBChartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBChartView.m; sourceTree = ""; }; 67 | FF3100501AC3FF740085C822 /* BBTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBTheme.h; sourceTree = ""; }; 68 | FF3100511AC3FF740085C822 /* BBTheme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBTheme.m; sourceTree = ""; }; 69 | FF3100531AC3FF740085C822 /* BarSeries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BarSeries.h; sourceTree = ""; }; 70 | FF3100541AC3FF740085C822 /* BarSeries.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BarSeries.m; sourceTree = ""; }; 71 | FF3100551AC3FF740085C822 /* Series.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Series.h; sourceTree = ""; }; 72 | FF3100561AC3FF740085C822 /* Series.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Series.m; sourceTree = ""; }; 73 | FF3100571AC3FF740085C822 /* StockSeries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StockSeries.h; sourceTree = ""; }; 74 | FF3100581AC3FF740085C822 /* StockSeries.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StockSeries.m; sourceTree = ""; }; 75 | FF3100631AC3FFDE0085C822 /* BBStockChart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BBStockChart.h; sourceTree = ""; }; 76 | FF3100661AC4063A0085C822 /* data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = data.json; sourceTree = SOURCE_ROOT; }; 77 | FF6FB8741B14895E006F33BA /* LineSeries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineSeries.h; sourceTree = ""; }; 78 | FF6FB8751B14895E006F33BA /* LineSeries.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LineSeries.m; sourceTree = ""; }; 79 | /* End PBXFileReference section */ 80 | 81 | /* Begin PBXFrameworksBuildPhase section */ 82 | FF3100151AC3FF560085C822 /* Frameworks */ = { 83 | isa = PBXFrameworksBuildPhase; 84 | buildActionMask = 2147483647; 85 | files = ( 86 | ); 87 | runOnlyForDeploymentPostprocessing = 0; 88 | }; 89 | FF31002E1AC3FF570085C822 /* Frameworks */ = { 90 | isa = PBXFrameworksBuildPhase; 91 | buildActionMask = 2147483647; 92 | files = ( 93 | ); 94 | runOnlyForDeploymentPostprocessing = 0; 95 | }; 96 | /* End PBXFrameworksBuildPhase section */ 97 | 98 | /* Begin PBXGroup section */ 99 | FF31000F1AC3FF560085C822 = { 100 | isa = PBXGroup; 101 | children = ( 102 | FF3100411AC3FF740085C822 /* BBStockChartView */, 103 | FF31001A1AC3FF560085C822 /* BBStockChartViewDemo */, 104 | FF3100341AC3FF570085C822 /* BBStockChartViewDemoTests */, 105 | FF3100191AC3FF560085C822 /* Products */, 106 | ); 107 | sourceTree = ""; 108 | }; 109 | FF3100191AC3FF560085C822 /* Products */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | FF3100181AC3FF560085C822 /* BBStockChartViewDemo.app */, 113 | FF3100311AC3FF570085C822 /* BBStockChartViewDemoTests.xctest */, 114 | ); 115 | name = Products; 116 | sourceTree = ""; 117 | }; 118 | FF31001A1AC3FF560085C822 /* BBStockChartViewDemo */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | FF3100661AC4063A0085C822 /* data.json */, 122 | FF31001F1AC3FF570085C822 /* AppDelegate.h */, 123 | FF3100201AC3FF570085C822 /* AppDelegate.m */, 124 | FF3100221AC3FF570085C822 /* ViewController.h */, 125 | FF3100231AC3FF570085C822 /* ViewController.m */, 126 | FF3100251AC3FF570085C822 /* Main.storyboard */, 127 | FF3100281AC3FF570085C822 /* Images.xcassets */, 128 | FF31002A1AC3FF570085C822 /* LaunchScreen.xib */, 129 | FF31001B1AC3FF560085C822 /* Supporting Files */, 130 | ); 131 | path = BBStockChartViewDemo; 132 | sourceTree = ""; 133 | }; 134 | FF31001B1AC3FF560085C822 /* Supporting Files */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | FF31001C1AC3FF560085C822 /* Info.plist */, 138 | FF31001D1AC3FF570085C822 /* main.m */, 139 | ); 140 | name = "Supporting Files"; 141 | sourceTree = ""; 142 | }; 143 | FF3100341AC3FF570085C822 /* BBStockChartViewDemoTests */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | FF3100371AC3FF570085C822 /* BBStockChartViewDemoTests.m */, 147 | FF3100351AC3FF570085C822 /* Supporting Files */, 148 | ); 149 | path = BBStockChartViewDemoTests; 150 | sourceTree = ""; 151 | }; 152 | FF3100351AC3FF570085C822 /* Supporting Files */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | FF3100361AC3FF570085C822 /* Info.plist */, 156 | ); 157 | name = "Supporting Files"; 158 | sourceTree = ""; 159 | }; 160 | FF3100411AC3FF740085C822 /* BBStockChartView */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | FF3100431AC3FF740085C822 /* Area.h */, 164 | FF3100441AC3FF740085C822 /* Area.m */, 165 | FF3100421AC3FF740085C822 /* Area */, 166 | FF3100451AC3FF740085C822 /* Axis */, 167 | FF31004A1AC3FF740085C822 /* BaseLayer.h */, 168 | FF31004B1AC3FF740085C822 /* BaseLayer.m */, 169 | FF31004C1AC3FF740085C822 /* BBChartUtils.h */, 170 | FF31004D1AC3FF740085C822 /* BBChartUtils.m */, 171 | FF31004E1AC3FF740085C822 /* BBChartView.h */, 172 | FF31004F1AC3FF740085C822 /* BBChartView.m */, 173 | FF3100501AC3FF740085C822 /* BBTheme.h */, 174 | FF3100511AC3FF740085C822 /* BBTheme.m */, 175 | FF3100521AC3FF740085C822 /* Series */, 176 | FF3100631AC3FFDE0085C822 /* BBStockChart.h */, 177 | ); 178 | name = BBStockChartView; 179 | path = ../BBStockChartView; 180 | sourceTree = ""; 181 | }; 182 | FF3100421AC3FF740085C822 /* Area */ = { 183 | isa = PBXGroup; 184 | children = ( 185 | ); 186 | path = Area; 187 | sourceTree = ""; 188 | }; 189 | FF3100451AC3FF740085C822 /* Axis */ = { 190 | isa = PBXGroup; 191 | children = ( 192 | FF3100461AC3FF740085C822 /* AxisX.h */, 193 | FF3100471AC3FF740085C822 /* AxisX.m */, 194 | FF3100481AC3FF740085C822 /* AxisY.h */, 195 | FF3100491AC3FF740085C822 /* AxisY.m */, 196 | ); 197 | path = Axis; 198 | sourceTree = ""; 199 | }; 200 | FF3100521AC3FF740085C822 /* Series */ = { 201 | isa = PBXGroup; 202 | children = ( 203 | FF3100531AC3FF740085C822 /* BarSeries.h */, 204 | FF3100541AC3FF740085C822 /* BarSeries.m */, 205 | FF3100551AC3FF740085C822 /* Series.h */, 206 | FF3100561AC3FF740085C822 /* Series.m */, 207 | FF3100571AC3FF740085C822 /* StockSeries.h */, 208 | FF3100581AC3FF740085C822 /* StockSeries.m */, 209 | FF6FB8741B14895E006F33BA /* LineSeries.h */, 210 | FF6FB8751B14895E006F33BA /* LineSeries.m */, 211 | ); 212 | path = Series; 213 | sourceTree = ""; 214 | }; 215 | /* End PBXGroup section */ 216 | 217 | /* Begin PBXNativeTarget section */ 218 | FF3100171AC3FF560085C822 /* BBStockChartViewDemo */ = { 219 | isa = PBXNativeTarget; 220 | buildConfigurationList = FF31003B1AC3FF570085C822 /* Build configuration list for PBXNativeTarget "BBStockChartViewDemo" */; 221 | buildPhases = ( 222 | FF3100141AC3FF560085C822 /* Sources */, 223 | FF3100151AC3FF560085C822 /* Frameworks */, 224 | FF3100161AC3FF560085C822 /* Resources */, 225 | ); 226 | buildRules = ( 227 | ); 228 | dependencies = ( 229 | ); 230 | name = BBStockChartViewDemo; 231 | productName = BBStockChartViewDemo; 232 | productReference = FF3100181AC3FF560085C822 /* BBStockChartViewDemo.app */; 233 | productType = "com.apple.product-type.application"; 234 | }; 235 | FF3100301AC3FF570085C822 /* BBStockChartViewDemoTests */ = { 236 | isa = PBXNativeTarget; 237 | buildConfigurationList = FF31003E1AC3FF570085C822 /* Build configuration list for PBXNativeTarget "BBStockChartViewDemoTests" */; 238 | buildPhases = ( 239 | FF31002D1AC3FF570085C822 /* Sources */, 240 | FF31002E1AC3FF570085C822 /* Frameworks */, 241 | FF31002F1AC3FF570085C822 /* Resources */, 242 | ); 243 | buildRules = ( 244 | ); 245 | dependencies = ( 246 | FF3100331AC3FF570085C822 /* PBXTargetDependency */, 247 | ); 248 | name = BBStockChartViewDemoTests; 249 | productName = BBStockChartViewDemoTests; 250 | productReference = FF3100311AC3FF570085C822 /* BBStockChartViewDemoTests.xctest */; 251 | productType = "com.apple.product-type.bundle.unit-test"; 252 | }; 253 | /* End PBXNativeTarget section */ 254 | 255 | /* Begin PBXProject section */ 256 | FF3100101AC3FF560085C822 /* Project object */ = { 257 | isa = PBXProject; 258 | attributes = { 259 | CLASSPREFIX = ""; 260 | LastUpgradeCheck = 0820; 261 | ORGANIZATIONNAME = ChenXiaoyu; 262 | TargetAttributes = { 263 | FF3100171AC3FF560085C822 = { 264 | CreatedOnToolsVersion = 6.1.1; 265 | DevelopmentTeam = JT5K9NWG8Q; 266 | ProvisioningStyle = Automatic; 267 | }; 268 | FF3100301AC3FF570085C822 = { 269 | CreatedOnToolsVersion = 6.1.1; 270 | TestTargetID = FF3100171AC3FF560085C822; 271 | }; 272 | }; 273 | }; 274 | buildConfigurationList = FF3100131AC3FF560085C822 /* Build configuration list for PBXProject "BBStockChartViewDemo" */; 275 | compatibilityVersion = "Xcode 3.2"; 276 | developmentRegion = English; 277 | hasScannedForEncodings = 0; 278 | knownRegions = ( 279 | en, 280 | Base, 281 | ); 282 | mainGroup = FF31000F1AC3FF560085C822; 283 | productRefGroup = FF3100191AC3FF560085C822 /* Products */; 284 | projectDirPath = ""; 285 | projectRoot = ""; 286 | targets = ( 287 | FF3100171AC3FF560085C822 /* BBStockChartViewDemo */, 288 | FF3100301AC3FF570085C822 /* BBStockChartViewDemoTests */, 289 | ); 290 | }; 291 | /* End PBXProject section */ 292 | 293 | /* Begin PBXResourcesBuildPhase section */ 294 | FF3100161AC3FF560085C822 /* Resources */ = { 295 | isa = PBXResourcesBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | FF3100271AC3FF570085C822 /* Main.storyboard in Resources */, 299 | FF31002C1AC3FF570085C822 /* LaunchScreen.xib in Resources */, 300 | FF3100291AC3FF570085C822 /* Images.xcassets in Resources */, 301 | FF3100671AC4063A0085C822 /* data.json in Resources */, 302 | ); 303 | runOnlyForDeploymentPostprocessing = 0; 304 | }; 305 | FF31002F1AC3FF570085C822 /* Resources */ = { 306 | isa = PBXResourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | ); 310 | runOnlyForDeploymentPostprocessing = 0; 311 | }; 312 | /* End PBXResourcesBuildPhase section */ 313 | 314 | /* Begin PBXSourcesBuildPhase section */ 315 | FF3100141AC3FF560085C822 /* Sources */ = { 316 | isa = PBXSourcesBuildPhase; 317 | buildActionMask = 2147483647; 318 | files = ( 319 | FF31005D1AC3FF740085C822 /* BBChartUtils.m in Sources */, 320 | FF3100621AC3FF740085C822 /* StockSeries.m in Sources */, 321 | FF31005B1AC3FF740085C822 /* AxisY.m in Sources */, 322 | FF3100241AC3FF570085C822 /* ViewController.m in Sources */, 323 | FF3100211AC3FF570085C822 /* AppDelegate.m in Sources */, 324 | FF31005A1AC3FF740085C822 /* AxisX.m in Sources */, 325 | FF3100591AC3FF740085C822 /* Area.m in Sources */, 326 | FF3100611AC3FF740085C822 /* Series.m in Sources */, 327 | FF6FB8761B14895E006F33BA /* LineSeries.m in Sources */, 328 | FF31001E1AC3FF570085C822 /* main.m in Sources */, 329 | FF31005C1AC3FF740085C822 /* BaseLayer.m in Sources */, 330 | FF31005E1AC3FF740085C822 /* BBChartView.m in Sources */, 331 | FF3100601AC3FF740085C822 /* BarSeries.m in Sources */, 332 | FF31005F1AC3FF740085C822 /* BBTheme.m in Sources */, 333 | ); 334 | runOnlyForDeploymentPostprocessing = 0; 335 | }; 336 | FF31002D1AC3FF570085C822 /* Sources */ = { 337 | isa = PBXSourcesBuildPhase; 338 | buildActionMask = 2147483647; 339 | files = ( 340 | FF3100381AC3FF570085C822 /* BBStockChartViewDemoTests.m in Sources */, 341 | ); 342 | runOnlyForDeploymentPostprocessing = 0; 343 | }; 344 | /* End PBXSourcesBuildPhase section */ 345 | 346 | /* Begin PBXTargetDependency section */ 347 | FF3100331AC3FF570085C822 /* PBXTargetDependency */ = { 348 | isa = PBXTargetDependency; 349 | target = FF3100171AC3FF560085C822 /* BBStockChartViewDemo */; 350 | targetProxy = FF3100321AC3FF570085C822 /* PBXContainerItemProxy */; 351 | }; 352 | /* End PBXTargetDependency section */ 353 | 354 | /* Begin PBXVariantGroup section */ 355 | FF3100251AC3FF570085C822 /* Main.storyboard */ = { 356 | isa = PBXVariantGroup; 357 | children = ( 358 | FF3100261AC3FF570085C822 /* Base */, 359 | ); 360 | name = Main.storyboard; 361 | sourceTree = ""; 362 | }; 363 | FF31002A1AC3FF570085C822 /* LaunchScreen.xib */ = { 364 | isa = PBXVariantGroup; 365 | children = ( 366 | FF31002B1AC3FF570085C822 /* Base */, 367 | ); 368 | name = LaunchScreen.xib; 369 | sourceTree = ""; 370 | }; 371 | /* End PBXVariantGroup section */ 372 | 373 | /* Begin XCBuildConfiguration section */ 374 | FF3100391AC3FF570085C822 /* Debug */ = { 375 | isa = XCBuildConfiguration; 376 | buildSettings = { 377 | ALWAYS_SEARCH_USER_PATHS = YES; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BOOL_CONVERSION = YES; 383 | CLANG_WARN_CONSTANT_CONVERSION = YES; 384 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 385 | CLANG_WARN_EMPTY_BODY = YES; 386 | CLANG_WARN_ENUM_CONVERSION = YES; 387 | CLANG_WARN_INFINITE_RECURSION = YES; 388 | CLANG_WARN_INT_CONVERSION = YES; 389 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNREACHABLE_CODE = YES; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | CODE_SIGN_IDENTITY = "iPhone Developer"; 394 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 395 | COPY_PHASE_STRIP = NO; 396 | ENABLE_STRICT_OBJC_MSGSEND = YES; 397 | ENABLE_TESTABILITY = YES; 398 | GCC_C_LANGUAGE_STANDARD = gnu99; 399 | GCC_DYNAMIC_NO_PIC = NO; 400 | GCC_NO_COMMON_BLOCKS = YES; 401 | GCC_OPTIMIZATION_LEVEL = 0; 402 | GCC_PREPROCESSOR_DEFINITIONS = ( 403 | "DEBUG=1", 404 | "$(inherited)", 405 | ); 406 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 407 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 408 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 409 | GCC_WARN_UNDECLARED_SELECTOR = YES; 410 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 411 | GCC_WARN_UNUSED_FUNCTION = YES; 412 | GCC_WARN_UNUSED_VARIABLE = YES; 413 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 414 | MTL_ENABLE_DEBUG_INFO = YES; 415 | ONLY_ACTIVE_ARCH = YES; 416 | SDKROOT = iphoneos; 417 | TARGETED_DEVICE_FAMILY = "1,2"; 418 | }; 419 | name = Debug; 420 | }; 421 | FF31003A1AC3FF570085C822 /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | ALWAYS_SEARCH_USER_PATHS = YES; 425 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 426 | CLANG_CXX_LIBRARY = "libc++"; 427 | CLANG_ENABLE_MODULES = YES; 428 | CLANG_ENABLE_OBJC_ARC = YES; 429 | CLANG_WARN_BOOL_CONVERSION = YES; 430 | CLANG_WARN_CONSTANT_CONVERSION = YES; 431 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 432 | CLANG_WARN_EMPTY_BODY = YES; 433 | CLANG_WARN_ENUM_CONVERSION = YES; 434 | CLANG_WARN_INFINITE_RECURSION = YES; 435 | CLANG_WARN_INT_CONVERSION = YES; 436 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 437 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 438 | CLANG_WARN_UNREACHABLE_CODE = YES; 439 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 440 | CODE_SIGN_IDENTITY = "iPhone Developer"; 441 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 442 | COPY_PHASE_STRIP = YES; 443 | ENABLE_NS_ASSERTIONS = NO; 444 | ENABLE_STRICT_OBJC_MSGSEND = YES; 445 | GCC_C_LANGUAGE_STANDARD = gnu99; 446 | GCC_NO_COMMON_BLOCKS = YES; 447 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 448 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 449 | GCC_WARN_UNDECLARED_SELECTOR = YES; 450 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 451 | GCC_WARN_UNUSED_FUNCTION = YES; 452 | GCC_WARN_UNUSED_VARIABLE = YES; 453 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 454 | MTL_ENABLE_DEBUG_INFO = NO; 455 | SDKROOT = iphoneos; 456 | TARGETED_DEVICE_FAMILY = "1,2"; 457 | VALIDATE_PRODUCT = YES; 458 | }; 459 | name = Release; 460 | }; 461 | FF31003C1AC3FF570085C822 /* Debug */ = { 462 | isa = XCBuildConfiguration; 463 | buildSettings = { 464 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 465 | CODE_SIGN_IDENTITY = "iPhone Developer"; 466 | "CODE_SIGN_IDENTITY[sdk=*]" = "iPhone Developer"; 467 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 468 | DEVELOPMENT_TEAM = JT5K9NWG8Q; 469 | INFOPLIST_FILE = BBStockChartViewDemo/Info.plist; 470 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 471 | PRODUCT_BUNDLE_IDENTIFIER = com.chenxiaoyu.BBStockChartViewDemo; 472 | PRODUCT_NAME = "$(TARGET_NAME)"; 473 | PROVISIONING_PROFILE = ""; 474 | }; 475 | name = Debug; 476 | }; 477 | FF31003D1AC3FF570085C822 /* Release */ = { 478 | isa = XCBuildConfiguration; 479 | buildSettings = { 480 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 481 | CODE_SIGN_IDENTITY = "iPhone Developer"; 482 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 483 | DEVELOPMENT_TEAM = JT5K9NWG8Q; 484 | INFOPLIST_FILE = BBStockChartViewDemo/Info.plist; 485 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 486 | PRODUCT_BUNDLE_IDENTIFIER = com.chenxiaoyu.BBStockChartViewDemo; 487 | PRODUCT_NAME = "$(TARGET_NAME)"; 488 | PROVISIONING_PROFILE = ""; 489 | }; 490 | name = Release; 491 | }; 492 | FF31003F1AC3FF570085C822 /* Debug */ = { 493 | isa = XCBuildConfiguration; 494 | buildSettings = { 495 | BUNDLE_LOADER = "$(TEST_HOST)"; 496 | FRAMEWORK_SEARCH_PATHS = ( 497 | "$(SDKROOT)/Developer/Library/Frameworks", 498 | "$(inherited)", 499 | ); 500 | GCC_PREPROCESSOR_DEFINITIONS = ( 501 | "DEBUG=1", 502 | "$(inherited)", 503 | ); 504 | INFOPLIST_FILE = BBStockChartViewDemoTests/Info.plist; 505 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 506 | PRODUCT_BUNDLE_IDENTIFIER = "com.chenxiaoyu.$(PRODUCT_NAME:rfc1034identifier)"; 507 | PRODUCT_NAME = "$(TARGET_NAME)"; 508 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BBStockChartViewDemo.app/BBStockChartViewDemo"; 509 | }; 510 | name = Debug; 511 | }; 512 | FF3100401AC3FF570085C822 /* Release */ = { 513 | isa = XCBuildConfiguration; 514 | buildSettings = { 515 | BUNDLE_LOADER = "$(TEST_HOST)"; 516 | FRAMEWORK_SEARCH_PATHS = ( 517 | "$(SDKROOT)/Developer/Library/Frameworks", 518 | "$(inherited)", 519 | ); 520 | INFOPLIST_FILE = BBStockChartViewDemoTests/Info.plist; 521 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 522 | PRODUCT_BUNDLE_IDENTIFIER = "com.chenxiaoyu.$(PRODUCT_NAME:rfc1034identifier)"; 523 | PRODUCT_NAME = "$(TARGET_NAME)"; 524 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BBStockChartViewDemo.app/BBStockChartViewDemo"; 525 | }; 526 | name = Release; 527 | }; 528 | /* End XCBuildConfiguration section */ 529 | 530 | /* Begin XCConfigurationList section */ 531 | FF3100131AC3FF560085C822 /* Build configuration list for PBXProject "BBStockChartViewDemo" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | FF3100391AC3FF570085C822 /* Debug */, 535 | FF31003A1AC3FF570085C822 /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | defaultConfigurationName = Release; 539 | }; 540 | FF31003B1AC3FF570085C822 /* Build configuration list for PBXNativeTarget "BBStockChartViewDemo" */ = { 541 | isa = XCConfigurationList; 542 | buildConfigurations = ( 543 | FF31003C1AC3FF570085C822 /* Debug */, 544 | FF31003D1AC3FF570085C822 /* Release */, 545 | ); 546 | defaultConfigurationIsVisible = 0; 547 | defaultConfigurationName = Release; 548 | }; 549 | FF31003E1AC3FF570085C822 /* Build configuration list for PBXNativeTarget "BBStockChartViewDemoTests" */ = { 550 | isa = XCConfigurationList; 551 | buildConfigurations = ( 552 | FF31003F1AC3FF570085C822 /* Debug */, 553 | FF3100401AC3FF570085C822 /* Release */, 554 | ); 555 | defaultConfigurationIsVisible = 0; 556 | defaultConfigurationName = Release; 557 | }; 558 | /* End XCConfigurationList section */ 559 | }; 560 | rootObject = FF3100101AC3FF560085C822 /* Project object */; 561 | } 562 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BBStockChart.h" 11 | 12 | @interface ViewController : UIViewController 13 | 14 | @property (nonatomic) BBChartView* chartView; 15 | @property (nonatomic) NSArray* chartData; 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "BBStockChart.h" 11 | 12 | #define Float(a) (((NSNumber*)a).floatValue) 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | //init with any size, autolayout 23 | _chartView = [[BBChartView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; 24 | [self.view addSubview:_chartView]; 25 | // a sample data file stored in data.json 26 | [self loadData]; 27 | 28 | // if you want to clear the data 29 | //[_chartView reset]; 30 | 31 | //ChartView add area, area add series 32 | Area* areaup = [[Area alloc] init]; 33 | //set delegate for axis's data provider 34 | areaup.bottomAxis.labelProvider = self; 35 | Area* areadown = [[Area alloc] init]; 36 | areadown.bottomAxis.labelProvider = self; 37 | BarSeries* bar = [[BarSeries alloc] init]; 38 | StockSeries* stock = [[StockSeries alloc] init]; 39 | LineSeries* line = [[LineSeries alloc] init]; 40 | line.color = [UIColor yellowColor]; 41 | line.width = 1.5; 42 | 43 | LineSeries* line2 = [[LineSeries alloc] init]; 44 | line2.color = [UIColor grayColor]; 45 | [areaup addSeries:stock]; 46 | [areadown addSeries:bar]; 47 | [areaup addSeries:line]; 48 | [areaup addSeries:line2]; 49 | 50 | for (NSArray* arr in _chartData) { 51 | [bar addPoint:Float(arr[1])]; 52 | [stock addPointOpen:Float(arr[2]) close:Float(arr[5]) low:Float(arr[4]) high:Float(arr[3])]; 53 | [line addPoint: (Float(arr[2]) + Float(arr[5]))/2 - 300]; 54 | [line2 addPoint:(Float(arr[4]) + Float(arr[3]))/2]; 55 | } 56 | [self.chartView addArea:areaup]; 57 | [self.chartView addArea:areadown]; 58 | // two area's height ratio 59 | [self.chartView setHeighRatio:0.3 forArea:areadown]; 60 | 61 | // set any color you like 62 | [BBTheme theme].barBorderColor = [UIColor clearColor]; 63 | [BBTheme theme].xAxisFontSize = 11; 64 | 65 | // begin to show the view animated 66 | [self.chartView drawAnimated:YES]; 67 | } 68 | 69 | - (void)loadData{ 70 | NSData *jsonData = [[NSData alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"]]; 71 | NSError* err = nil; 72 | _chartData = (NSArray*)[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&err]; 73 | } 74 | 75 | #pragma mark - AxisDataProvider 76 | - (NSString *)textForIdx:(NSUInteger)idx{ 77 | NSString* ret = nil; 78 | 79 | // Too much labels would make them overlapping 80 | if (idx % 15 == 0) { 81 | NSDate* curDate = [NSDate date]; 82 | NSDate* date = nil; 83 | NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; 84 | NSDateComponents* dateComponents = [[NSDateComponents alloc] init]; 85 | NSCalendar *calendar = [NSCalendar currentCalendar]; 86 | // idx - 90, is meaningless for your data. 87 | [dateComponents setDay:idx-90]; 88 | formatter.dateFormat = @"MM/dd HH:00";; 89 | date = [calendar dateByAddingComponents:dateComponents toDate:curDate options:0]; 90 | ret = [formatter stringFromDate:date]; 91 | } 92 | 93 | return ret; 94 | 95 | } 96 | 97 | - (void)didReceiveMemoryWarning { 98 | [super didReceiveMemoryWarning]; 99 | // Dispose of any resources that can be recreated. 100 | } 101 | 102 | - (NSUInteger)supportedInterfaceOrientations { 103 | return UIInterfaceOrientationMaskLandscape; 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BBStockChartViewDemo 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemoTests/BBStockChartViewDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBStockChartViewDemoTests.m 3 | // BBStockChartViewDemoTests 4 | // 5 | // Created by ChenXiaoyu on 15/3/26. 6 | // Copyright (c) 2015年 ChenXiaoyu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface BBStockChartViewDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation BBStockChartViewDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/BBStockChartViewDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /BBStockChartViewDemo/Screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenxiaoyu3/BBStockChartView/8ba04919378304013ecd2e0c5fd17a9f6307cf46/BBStockChartViewDemo/Screenshots/1.png -------------------------------------------------------------------------------- /BBStockChartViewDemo/Screenshots/v1.1.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenxiaoyu3/BBStockChartView/8ba04919378304013ecd2e0c5fd17a9f6307cf46/BBStockChartViewDemo/Screenshots/v1.1.0.png -------------------------------------------------------------------------------- /BBStockChartViewDemo/data.json: -------------------------------------------------------------------------------- 1 | [[1419436800000,517.676951,2064,2085.2,1965.2,1982],[1419523200000,330.459166,1982.1,2019.9,1955,2014],[1419609600000,490.265944,2002.2,2063.9,1940,1957.3],[1419696000000,317.025368,1957.2,1979,1929,1965.4],[1419782400000,303.59848,1962.9,1992.6,1940,1947],[1419868800000,390.538623,1948,1960.2,1912,1925],[1419955200000,214.813718,1923,1944,1913,1938.5],[1420041600000,260.354078,1938.5,1970,1932.3,1955],[1420128000000,212.618523,1951.3,1961.1,1933,1945],[1420214400000,690.056036,1953,1962,1851,1866],[1420300800000,1082.088695,1857,1873,1581.9,1630],[1420387200000,863.6687,1630,1725.5,1610,1676.9],[1420473600000,389.903054,1682.9,1715,1653,1689.9],[1420560000000,482.965655,1689.9,1759.4,1683,1748.9],[1420646400000,464.743793,1749,1808.9,1722,1738.9],[1420732800000,239.229695,1734,1762.7,1717.3,1739.8],[1420819200000,457.795921,1741,1770.8,1663,1679.9],[1420905600000,477.371049,1679.9,1704,1636.1,1645.9],[1420992000000,413.462895,1654.9,1683.8,1617.3,1671.9],[1421078400000,1202.171187,1675,1680,1411,1440],[1421164800000,3351.243944,1440,1459.3,1033.3,1181],[1421251200000,2619.82914,1184,1341.7,1024.4,1295],[1421337600000,1326.430661,1300,1360,1220.6,1262],[1421424000000,670.727045,1262,1306.5,1181.8,1203],[1421510400000,1113.986809,1209,1350,1181.8,1297.9],[1421596800000,574.792111,1297.7,1327,1255,1281.1],[1421683200000,498.954306,1285,1320,1258.3,1291.5],[1421769600000,784.348434,1291.5,1310,1290,1298],[1421856000000,2506.899502,1298,1467,1294.6,1416.2],[1421942400000,640.163592,1417,1450,1375,1432],[1422028800000,624.939439,1430.5,1510.9,1416.9,1493.8],[1422115200000,785.791771,1496,1582.6,1485.5,1511],[1422201600000,2767.547354,1515.9,1929.5,1498.5,1669.3],[1422288000000,1372.519555,1665,1705.7,1551,1617.9],[1422374400000,403.287159,1610,1664.9,1570,1599.6],[1422460800000,1118.910509,1591.7,1592.9,1380,1444.2],[1422547200000,769.258943,1431,1508,1407.1,1419.8],[1422633600000,396.6696,1423.5,1450,1404,1430],[1422720000000,658.655609,1426.1,1435.1,1306.4,1343.3],[1422806400000,573.583307,1349.1,1442.2,1347.6,1398.8],[1422892800000,761.812555,1393,1547.7,1389.9,1475],[1422979200000,663.44617,1476,1491.1,1371.2,1405.5],[1423065600000,398.241931,1400,1430.9,1350,1350.2],[1423152000000,455.710804,1351.3,1398,1335,1388],[1423238400000,269.368379,1398,1430,1382,1400.9],[1423324800000,251.925431,1393.5,1440,1380,1380.7],[1423411200000,263.672691,1380,1395.9,1350,1358],[1423497600000,193.605319,1364.8,1374,1338,1346],[1423584000000,319.048149,1342.4,1398.1,1340,1382],[1423670400000,200.372741,1372.6,1389.6,1350.1,1364],[1423756800000,332.8462,1365,1479,1362.4,1474],[1423843200000,642.408214,1478.9,1560,1454.5,1536.3],[1423929600000,968.653087,1535.5,1664.9,1506.4,1519.4],[1424016000000,471.521353,1522.4,1544.7,1415.5,1457.1],[1424102400000,192.604467,1457.1,1502.8,1450,1489.7],[1424188800000,241.791656,1497.9,1534.3,1468,1468],[1424275200000,229.645835,1479.7,1488.9,1450,1474],[1424361600000,203.375515,1486.2,1549.8,1479.3,1523.6],[1424448000000,175.326586,1513.6,1544,1504.3,1524.9],[1424534400000,239.26119,1515.6,1539.6,1460.8,1473],[1424620800000,137.205105,1473,1484.6,1450,1470],[1424707200000,158.811359,1475,1500.3,1468,1476],[1424793600000,128.940659,1480,1497.5,1470,1490],[1424880000000,279.571722,1490,1493.4,1463,1478],[1424966400000,828.841576,1478,1637,1468.6,1583.5],[1425052800000,326.141684,1583.5,1613.7,1562.3,1578.3],[1425139200000,313.359035,1578,1601,1540.1,1562.4],[1425225600000,375.243229,1552.3,1655,1552.3,1635],[1425312000000,753.165949,1641.8,1750,1625.9,1690.7],[1425398400000,672.922525,1690.7,1790,1683.8,1766.8],[1425484800000,560.615729,1760,1777,1672.2,1692.6],[1425571200000,317.216382,1692.3,1740,1650,1695],[1425657600000,141.364571,1704.5,1720,1676.5,1704],[1425744000000,228.596338,1707.7,1728.5,1690.2,1700.5],[1425830400000,379.474879,1703,1776.9,1695,1764],[1425916800000,613.774396,1770,1888.8,1764,1825],[1426003200000,399.151412,1829.9,1859.9,1813.1,1855],[1426089600000,260.486985,1855,1863.8,1822.9,1835.1],[1426176000000,394.718095,1835.1,1861,1789,1817],[1426262400000,406.835665,1825.8,1831.6,1761.1,1783.9],[1426348800000,278.185909,1779,1795.4,1763.6,1786],[1426435200000,357.822736,1786,1847,1779.2,1832],[1426521600000,265.523415,1830,1835.2,1792,1792.2],[1426608000000,540.496939,1790.6,1799.7,1677,1692],[1426694400000,640.959858,1695,1701,1550.1,1610],[1426780800000,282.495803,1619.9,1646.9,1568,1627],[1426867200000,224.688957,1618,1635.1,1581,1613.1],[1426953600000,155.490183,1620,1626.9,1597,1609.2],[1427040000000,604.615547,1615,1675,1608,1654],[1427126400000,562.585914,1654,1663.1,1490,1516.7],[1427212800000,551.86892,1516.8,1540.6,1450,1535.1]] 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Rex ( Chen Xiaoyu, chenxiaoyu3@gmail.com ) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | StockChartView 2 | =============== 3 | 4 | A full customizable iOS stock chart view, K-Line, volume graph, with gesture supported. 5 | 6 | ![Screenshots](https://github.com/chenxiaoyu3/BBStockChartView/blob/master/BBStockChartViewDemo/Screenshots/v1.1.0.png) 7 | 8 | BBStockchartView is used in project [BBAltcoin](http://bbaltcoin.com/) in [AppStore](https://itunes.apple.com/tt/app/bb-kan-pan/id962337229?mt=8) and [Android](http://bbaltcoin.com/). The iOS source is [here](https://github.com/chenxiaoyu3/BBAltcoin-iOS). 9 | 10 | Installation 11 | ---------------- 12 | Using CocoaPods 13 | 14 | ```Pod 15 | pod 'BBStockChartView', '~> 1.3' 16 | ``` 17 | 18 | Or add all files in folder "BBStockChartView" to your project. 19 | Done! 20 | 21 | Usage 22 | ---------------- 23 | 24 | See the demo Xcode project for details 25 | 26 | 27 | ```Objective-C 28 | //init with any size, autolayout 29 | _chartView = [[BBChartView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; 30 | 31 | //ChartView add area, area add series 32 | Area* areaup = [[Area alloc] init]; 33 | Area* areadown = [[Area alloc] init]; 34 | BarSeries* bar = [[BarSeries alloc] init]; 35 | StockSeries* stock = [[StockSeries alloc] init]; 36 | [areaup addSeries:stock]; 37 | [areadown addSeries:bar]; 38 | 39 | // add data to bar and stock 40 | // [stock addPoint:] 41 | [self.chartView addArea:areaup]; 42 | [self.chartView addArea:areadown]; 43 | // two area's height ratio 44 | [self.chartView setHeighRatio:0.3 forArea:areadown]; 45 | 46 | // set any color you like 47 | [BBTheme theme].barBorderColor = [UIColor clearColor]; 48 | [BBTheme theme].xAxisFontSize = 11; 49 | 50 | // begin to show the view animated 51 | [self.chartView drawAnimated:YES]; 52 | ``` 53 | 54 | 55 | 56 | Contributing 57 | ------- 58 | We'll love contributions, please report bugs in the issue tracker, create pull request (on branch develop) and suggest new great features (also in the issue tracker). 59 | 60 | 61 | License 62 | ----------- 63 | BBStockChartView available under the MIT license, so feel free to use it in commercial and non-commercial projects. 64 | 65 | Author 66 | ------- 67 | Chen XiaoYu --------------------------------------------------------------------------------