推荐一个2012年就开源了的IOS股票K线图源码(可运行)

这个IOS的K线图源码出现的很早,早在2012年iphone 4的乔布斯时代就已经出现了,小编也是参考了此代码而做出来很多K线图项目,当然这个代码写的比较复杂,感兴趣的朋友可以研究研究。

这个IOS K线图源码作者是中国人:ZhiYu,目前在百度就职,大牛非常的低调。

 

 

截取部分代码-初始化K线图

-(void)initChart{
    NSMutableArray *padding = [@[@"20", @"20", @"20", @"20"] mutableCopy];
    [self.candleChart setPadding:padding];
    NSMutableArray *secs = [[NSMutableArray alloc] init];
    [secs addObject:@"4"];
    [secs addObject:@"1"];
    [secs addObject:@"1"];
    [self.candleChart addSections:3 withRatios:secs];
    [self.candleChart getSection:2].hidden = YES;
    [[self.candleChart sections][0] addYAxis:0];
    [[self.candleChart sections][1] addYAxis:0];
    [[self.candleChart sections][2] addYAxis:0];

    [self.candleChart getYAxis:2 withIndex:0].baseValueSticky = NO;
    [self.candleChart getYAxis:2 withIndex:0].symmetrical = NO;
    [self.candleChart getYAxis:0 withIndex:0].ext = 0.05;
    NSMutableArray *series = [[NSMutableArray alloc] init];
    NSMutableArray *secOne = [[NSMutableArray alloc] init];
    NSMutableArray *secTwo = [[NSMutableArray alloc] init];
    NSMutableArray *secThree = [[NSMutableArray alloc] init];

    //price
    NSMutableDictionary *serie = [[NSMutableDictionary alloc] init];
    NSMutableArray *data = [[NSMutableArray alloc] init];
    serie[@"name"] = @"price";
    serie[@"label"] = @"Price";
    serie[@"data"] = data;
    serie[@"type"] = @"candle";
    serie[@"yAxis"] = @"0";
    serie[@"section"] = @"0";
    serie[@"color"] = @"249,222,170";
    serie[@"negativeColor"] = @"249,222,170";
    serie[@"selectedColor"] = @"249,222,170";
    serie[@"negativeSelectedColor"] = @"249,222,17/**/0";
    serie[@"labelColor"] = @"176,52,52";
    serie[@"labelNegativeColor"] = @"77,143,42";
    [series addObject:serie];
    [secOne addObject:serie];

    //MA10
    serie = [[NSMutableDictionary alloc] init];
    data = [[NSMutableArray alloc] init];
    serie[@"name"] = @"ma10";
    serie[@"label"] = @"MA10";
    serie[@"data"] = data;
    serie[@"type"] = @"line";
    serie[@"yAxis"] = @"0";
    serie[@"section"] = @"0";
    serie[@"color"] = @"255,255,255";
    serie[@"negativeColor"] = @"255,255,255";
    serie[@"selectedColor"] = @"255,255,255";
    serie[@"negativeSelectedColor"] = @"255,255,255";
    [series addObject:serie];
    [secOne addObject:serie];

    //MA30
    serie = [[NSMutableDictionary alloc] init];
    data = [[NSMutableArray alloc] init];
    serie[@"name"] = @"ma30";
    serie[@"label"] = @"MA30";
    serie[@"data"] = data;
    serie[@"type"] = @"line";
    serie[@"yAxis"] = @"0";
    serie[@"section"] = @"0";
    serie[@"color"] = @"250,232,115";
    serie[@"negativeColor"] = @"250,232,115";
    serie[@"selectedColor"] = @"250,232,115";
    serie[@"negativeSelectedColor"] = @"250,232,115";
    [series addObject:serie];
    [secOne addObject:serie];

    //MA60
    serie = [[NSMutableDictionary alloc] init];
    data = [[NSMutableArray alloc] init];
    serie[@"name"] = /**/@"ma60";
    serie[@"label"] = @"MA60";
    serie[@"data"] = data;
    serie[@"type"] = @"line";
    serie[@"yAxis"] = @"0";
    serie[@"section"] = @"0";
    serie[@"color"] = @"232,115,250";
    serie[@"negativeColor"] = @"232,115,250";
    serie[@"selectedColor"] = @"232,115,250";
    serie[@"negativeSelectedColor"] = @"232,115,250";
    [series addObject:serie];
    [secOne addObject:serie];


    //VOL
    serie = [[NSMutableDictionary alloc] init];
    data = [[NSMutableArray alloc] init];
    serie[@"name"] = @"vol";
    serie[@"label"] = @"VOL";
    serie[@"data"] = data;
    serie[@"type"] = @"column";
    serie[@"yAxis"] = @"0";
    serie[@"section"] = @"1";
    serie[@"decimal"] = @"0";
    serie[@"color"] = @"176,52,52";
    serie[@"negativeColor"] = @"77,143,42";
    serie[@"selectedColor"] = @"176,52,52";
    serie[@"negativeSelectedColor"] = @"77,143,42";
    [series addObject:serie];
    [secTwo addObject:serie];

    //candleChart init
    [self.candleChart setSeries:series];

    [[self.candleChart sections][0] setSeries:secOne];
    [[self.candleChart sections][1] setSeries:secTwo];
    [[self.candleChart sections][2] setSeries:secThree];
    [[self.candleChart sections][2] setPaging:YES];


    NSString *indicatorsString =[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"indicators" ofType:@"json"] encoding:NSUTF8StringEncoding error:nil];

    if(indicatorsString != nil){
        NSArray *indicators = [indicatorsString objectFromJSONString];
        for(NSObject *indicator in indicators){
            if([indicator isKindOfClass:[NSArray class]]){
                NSMutableArray *arr = [[NSMutableArray alloc] init];
                for(NSDictionary *indic in indicator){
                    NSMutableDictionary *serie = [[NSMutableDictionary alloc] init];
                    [self setOptions:indic ForSerie:serie];
                    [arr addObject:serie];
                }
                [self.candleChart addSerie:arr];
            }else{
                NSDictionary *indic = (NSDictionary *)indicator;
                NSMutableDictionary *serie = [[NSMutableDictionary alloc] init];
                [self setOptions:indic ForSerie:serie];
                [self.candleChart addSerie:serie];
            }
        }
    }

    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 10.0/**/;
    pathAnimation.fromValue = @0.0f;
    pathAnimation.toValue = @1.0f;
    [self.candleChart.layer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];

}

 

大师兄修改版本说明

1、这个源码很早就出现了,之前都是用雅虎的财经数据接口做测试,现在Yahoo 财经接口已经用不了,所以大师兄选股开源了自己的股票数据接口供大家学习使用,大师兄的接口带宽比较小,所以大家仅做测试学习使用,请务必用于气体用途。

2、大师兄选股开源股票数据接口:
http://api.klines.dashixiong.cn/history/day/data/SH000001.txt

3、大师兄对CandleViewController.m文件进行链接地址和请求完成数据处理方法进行了修改,具体请看文件内容

4、数据来源:大师兄选股 http://www.dashixiong.cn

5、联系微信:dashixiongcn

6、版权归原作者所有

Github 地址

https://github.com/zhiyu/chartee

请自觉Star作者

 

本地下载(大师兄已做过数据请求和解析的修改,可运行)

 

分享到:

评论已关闭

  1. dangfm

    这个K线图的源码出现的很早,建议大家研究学习一下。