• iOS 超级实用K线图 2020-07-05 23:30:55
    iOSK线图
  • IOS 股票K线图的实现 2018-03-31 11:59:52
    2015-09-04 by 木易哥哥 智者精选,每天获取励志认知能量 www.5izhjx.com写了lines、RKLineView、getData三个对象完成实现。首先开始调用rkLine = [[RKLineViewalloc]init]; CGRect frame =riKView.frame;...

     2015-09-04 by 木易哥哥 

    智者精选,每天获取励志认知能量 www.5izhjx.com


    写了lines、RKLineView、getData三个对象完成实现。

    首先开始调用

    rkLine = [[RKLineViewalloc]init];

            CGRect frame =riKView.frame;

             frame.origin =CGPointMake(0,5);

             frame.size =CGSizeMake(315,219);

            rkLine.frame = frame;

            rkLine.xWidth =315;

            rkLine.yHeight =219;

             rkLine.kLineWidth =4;

             rkLine.kLinePadding =1.25;

            rkLine.riKArry = [dicobjectForKey:@"rows"];


             [riKViewaddSubview:rkLine];

             [rkLinestart];// 线图运行



    其它3个对象部分代码如下

    #import <UIKit/UIKit.h>


    @interface lines : UIView

    @property (nonatomic,assign)CGPoint startPoint;//线条起点

    @property (nonatomic,assign)CGPoint endPoint;//线条终点

    @property (nonatomic,retain)NSArray *points;//多点连线数组

    @property (nonatomic,retain)NSString *color;//线条颜色

    @property (nonatomic,assign)CGFloat lineWidth;//线条宽度

    @property (nonatomic,assign)BOOL isK;//是否是实体K线默认是连接线

    @property (nonatomic,assign)BOOL isVol;//是否是画成交量的实体

    @end



    #import "lines.h"

    #import "colorModel.h"

    #import "UIColor+helper.h"


    @interface lines(){


    }

    @end


    @implementation lines


    - (id)initWithFrame:(CGRect)frame

    {

       self = [superinitWithFrame:frame];

       if (self) {

            // Initialization code

            [selfinitSet];

        }

        return self;

    }


    #pragma mark 初始化参数

    -(void)initSet{

        self.backgroundColor = [UIColorclearColor];

       self.startPoint =self.frame.origin;

       self.endPoint =self.frame.origin;

        self.color =@"#000000";

       self.lineWidth =1.0f;

       self.isK =NO;

       self.isVol =NO;

    }



    -(void)drawRect:(CGRect)rect

    {

        CGContextRef context =UIGraphicsGetCurrentContext();//获取绘图上下文

       if (self.isK) {

           //k线

           for (NSArray *iteminself.points) {

               //转换坐标

               CGPoint heightPoint,lowPoint,openPoint,closePoint;

                heightPoint =CGPointFromString([itemobjectAtIndex:0]);

                lowPoint =CGPointFromString([itemobjectAtIndex:1]);

                openPoint =CGPointFromString([itemobjectAtIndex:2]);

                closePoint =CGPointFromString([itemobjectAtIndex:3]);

                [selfdrawKWithContext:contextheight:heightPoint Low:lowPoint open:openPoint close:closePoint width:self.lineWidth];

            }

            

        }else{

           //画连接线

            [selfdrawLineWithContext:context];

        }

    }

    #pragma mark 画连接线

    -(void)drawLineWithContext:(CGContextRef)context{

        CGContextSetLineWidth(context,self.lineWidth);

        //NSLog(@"self.lineWidth:%f",self.lineWidth);

        CGContextSetShouldAntialias(context,YES);

       colorModel *colormodel = [UIColorRGBWithHexString:self.colorwithAlpha:self.alpha];//设置颜色

       CGContextSetRGBStrokeColor(context, (CGFloat)colormodel.R/255.0f, (CGFloat)colormodel.G/255.0f, (CGFloat)colormodel.B/255.0f,self.alpha);

        if (self.startPoint.x==self.endPoint.x && self.endPoint.y==self.startPoint.y) {

            // 定义多个个点 画多点连线

           for (id iteminself.points) {

               CGPoint currentPoint =CGPointFromString(item);

               if ((int)currentPoint.y<(int)self.frame.size.height && currentPoint.y>0) {

                   if ([self.pointsindexOfObject:item]==0) {

                       CGContextMoveToPoint(context, currentPoint.x, currentPoint.y);

                       continue;

                    }

                   CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);

                   CGContextStrokePath(context);//开始画线

                   if ([self.pointsindexOfObject:item]<self.points.count) {

                       CGContextMoveToPoint(context, currentPoint.x, currentPoint.y);

                    }

                    

                }

            }

        }else{

            // 定义两个点 画两点连线

           constCGPoint points[] = {self.startPoint,self.endPoint};

           CGContextStrokeLineSegments(context, points,2);  // 绘制线段(默认不绘制端点)

        }

    }


    #pragma mark 画一根K线

    -(void)drawKWithContext:(CGContextRef)context height:(CGPoint)heightPoint Low:(CGPoint)lowPoint open:(CGPoint)openPoint close:(CGPoint)closePoint width:(CGFloat)width{

        CGContextSetShouldAntialias(context,NO);

        //首先判断是绿的还是红的,根据开盘价和收盘价的坐标来计算

       BOOL isKong =NO;

       colorModel *colormodel = [UIColorRGBWithHexString:@"#FF0000"withAlpha:self.alpha];//设置默认红色

        //如果开盘价坐标在收盘价坐标上方则为绿色即空

       if (openPoint.y<closePoint.y) {

            isKong =YES;

            colormodel = [UIColorRGBWithHexString:@"#00a900"withAlpha:self.alpha];//设置为绿色

        }

        // 设置颜色

       CGContextSetRGBStrokeColor(context, (CGFloat)colormodel.R/255.0f, (CGFloat)colormodel.G/255.0f, (CGFloat)colormodel.B/255.0f,self.alpha);

        //首先画一个垂直的线包含上影线和下影线

        //定义两个点画两点连线

       if (!self.isVol) {

           CGContextSetLineWidth(context,1); // 上下阴影线的宽度

           if (self.lineWidth<=2) {

               CGContextSetLineWidth(context,0.5); // 上下阴影线的宽度

            }

           constCGPoint points[] = {heightPoint,lowPoint};

           CGContextStrokeLineSegments(context, points,2);  // 绘制线段(默认不绘制端点)

        }

        // 再画中间的实体

       CGContextSetLineWidth(context, width);// 改变线的宽度

       CGFloat halfWidth =0;//width/2;

        //纠正实体的中心点为当前坐标

        openPoint =CGPointMake(openPoint.x-halfWidth, openPoint.y);

        closePoint =CGPointMake(closePoint.x-halfWidth, closePoint.y);

       if (self.isVol) {

            openPoint =CGPointMake(heightPoint.x-halfWidth, heightPoint.y);

            closePoint =CGPointMake(lowPoint.x-halfWidth, lowPoint.y);

        }

        // 开始画实体

       constCGPoint point[] = {openPoint,closePoint};

        CGContextStrokeLineSegments(context, point,2); // 绘制线段(默认不绘制端点)

    }



    @end


    #import <UIKit/UIKit.h>


    typedefvoid(^updateBlock)(id);


    @interface RKLineView :UIView


    @property (nonatomic,copy)updateBlock finishUpdateBlock; // 定义一个block回调更新界面


    @property (nonatomic,assign)CGFloat xWidth;// x轴宽度

    @property (nonatomic,assign)CGFloat yHeight;// y轴高度

    @property (nonatomic,assign)CGFloat bottomBoxHeight;// y轴高度

    @property (nonatomic,assign)CGFloat kLineWidth;// k线的宽度 用来计算可存放K线实体的个数,也可以由此计算出起始日期和结束日期的时间段

    @property (nonatomic,assign)CGFloat kLinePadding;

    @property (nonatomic,assign)int kCount;// k线中实体的总数 通过 xWidth / kLineWidth 计算而来

    @property (nonatomic,retain)UIFont *font;


    @property (nonatomic,retain)NSMutableArray *data;

    @property (nonatomic,retain)NSDate *startDate;

    @property (nonatomic,retain)NSDate *endDate;


    @property (nonatomic,retain)NSMutableArray *riKArry;//分时数据数组

    @property (nonatomic,retain)NSString *jrkp;//今日开盘

    @property (nonatomic,retain)NSString *zrsp;//昨日收盘


    -(void)start;

    -(void)update;

    @end


    #import "RKLineView.h"

    #import "lines.h"

    #import "UIColor+helper.h"

    #import "getData.h"

    #import "commond.h"


    @interface RKLineView()

    {

       NSThread *thread;

       UIView *mainboxView;// k线图控件

       UIView *bottomBoxView;// 成交量

       getData *getdata;

        

       UIView *movelineone;// 手指按下后显示的两根白色十字线

       UIView *movelinetwo;

        

       UIView *xxView;//展现信息

       UILabel *riqLable;//日期

       UILabel *kpLable;//开盘

       UILabel *zgLable;//最高

       UILabel *zdLable;//最低

       UILabel *spLable;//收盘

       UILabel *cjlLable;//成交量

       UILabel *cjeLable;//成交额

       UILabel *zflLable;//涨幅

        

       UILabel *movelinetwoLable;

        

       NSMutableArray *pointArray;// k线所有坐标数组

        

       UILabel *startDateLab;

       UILabel *endDateLab;

        

       UILabel *volMaxValueLab;// 显示成交量最大值

        

       BOOL isUpdate;

       BOOL isUpdateFinish;

        

       NSMutableArray *lineArray ;// k线数组

       NSMutableArray *lineOldArray ;// k线数组

        UIPinchGestureRecognizer *pinchGesture;

       CGPoint touchViewPoint;

       BOOL isPinch;

        

       UILabel *MA5;// 5均线显示

       UILabel *MA10;// 10均线

       UILabel *MA20;// 20均线

        

       UILabel *jg1;//价格1

       UILabel *jg2;//价格2

       UILabel *jg3;//价格3

       UILabel *jg4;//价格4

       UILabel *jg5;//价格5

        

       UILabel *zfl1;//涨幅率1

       UILabel *zfl2;//涨幅率2

       UILabel *zfl3;//涨幅率3

       UILabel *zfl4;//涨幅率4

       UILabel *zfl5;//涨幅率5

        

       UILabel *shou1;//1

       UILabel *shou2;//2

       UILabel *shou3;//3

    }

    @end


    @implementation RKLineView


    -(id)init{

       self = [superinit];

        [selfinitSet];

        return self;

    }


    -(void)initSet

    {

        

        self.font = [UIFontsystemFontOfSize:8];

       isUpdate =NO;

        isUpdateFinish =YES;

       isPinch =NO;

        

       lineArray = [[NSMutableArrayalloc]init];

       lineOldArray = [[NSMutableArrayalloc]init];

        

        self.finishUpdateBlock = ^(idself){

            [selfupdateNib];//十字线显示的view

        };

    }


    #pragma mark 更新界面等信息

    -(void)updateNib{

        //NSLog(@"block");

       if (movelineone==Nil) {

            movelineone = [[UIViewalloc]initWithFrame:CGRectMake(0,0,0.5,

                                                                  bottomBoxView.frame.size.height+bottomBoxView.frame.origin.y)];

            movelineone.backgroundColor = [UIColorcolorWithHexString:@"#333333"withAlpha:0.5];

            [mainboxViewaddSubview:movelineone];

           movelineone.hidden =YES;

        }

       if (movelinetwo==Nil) {

           movelinetwo = [[UIViewalloc]initWithFrame:CGRectMake(0,0,mainboxView.frame.size.width,1)];

            movelinetwo.backgroundColor = [UIColorcolorWithHexString:@"#333333"withAlpha:0.5];

           movelinetwo.hidden =YES;

            [mainboxViewaddSubview:movelinetwo];

        }

       if (xxView==Nil) {

           CGRect oneFrame =movelineone.frame;

            oneFrame.size =CGSizeMake(60,73);

           xxView = [[UIViewalloc]initWithFrame:oneFrame];

            xxView.backgroundColor = [UIColorcolorWithHexString:@"#333333"withAlpha:1];

           xxView.hidden =YES;

            

            riqLable = [[UILabelalloc]initWithFrame:CGRectMake(2,1,60,8)];

           riqLable.font = [UIFontsystemFontOfSize:8];

           riqLable.textColor = [UIColorwhiteColor];

            

            kpLable = [[UILabelalloc]initWithFrame:CGRectMake(2,10,60,8)];

           kpLable.font = [UIFontsystemFontOfSize:8];

           kpLable.textColor = [UIColorwhiteColor];

            

            zgLable = [[UILabelalloc]initWithFrame:CGRectMake(2,19,60,8)];

           zgLable.font = [UIFontsystemFontOfSize:8];

           zgLable.textColor = [UIColorwhiteColor];

            

            zdLable = [[UILabelalloc]initWithFrame:CGRectMake(2,28,60,8)];

           zdLable.font = [UIFontsystemFontOfSize:8];

           zdLable.textColor = [UIColorwhiteColor];

            

            spLable = [[UILabelalloc]initWithFrame:CGRectMake(2,37,60,8)];

           spLable.font = [UIFontsystemFontOfSize:8];

           spLable.textColor = [UIColorwhiteColor];

            

            cjlLable = [[UILabelalloc]initWithFrame:CGRectMake(2,46,60,8)];

           cjlLable.font = [UIFontsystemFontOfSize:8];

           cjlLable.textColor = [UIColorwhiteColor];

            

            cjeLable = [[UILabelalloc]initWithFrame:CGRectMake(2,55,60,8)];

           cjeLable.font = [UIFontsystemFontOfSize:8];

           cjeLable.textColor = [UIColorwhiteColor];

            

            zflLable = [[UILabelalloc]initWithFrame:CGRectMake(2,64,60,8)];

           zflLable.font = [UIFontsystemFontOfSize:8];

           zflLable.textColor = [UIColorwhiteColor];


            [xxView addSubview:riqLable];

            [xxViewaddSubview:kpLable];

            [xxViewaddSubview:zgLable];

            [xxViewaddSubview:zdLable];

            [xxViewaddSubview:spLable];

            [xxView addSubview:cjlLable];

            [xxView addSubview:cjeLable];

            [xxView addSubview:zflLable];

            [mainboxViewaddSubview:xxView];

        }

        if (movelinetwoLable==Nil) {

           CGRect oneFrame =movelinetwo.frame;

            oneFrame.size =CGSizeMake(36,12);

           movelinetwoLable = [[UILabelalloc]initWithFrame:oneFrame];

            movelinetwoLable.font =self.font;

            movelinetwoLable.layer.cornerRadius =5;

            movelinetwoLable.backgroundColor = [UIColorcolorWithHexString:@"#333333"withAlpha:1];

           movelinetwoLable.textColor = [UIColorwhiteColor];

            movelinetwoLable.textAlignment =UITextAlignmentCenter;

            movelinetwoLable.hidden =YES;

            [mainboxViewaddSubview:movelinetwoLable];

        }

        

        movelineone.frame =CGRectMake(touchViewPoint.x,0,0.5,

                                      bottomBoxView.frame.size.height+bottomBoxView.frame.origin.y);

        movelinetwo.frame =CGRectMake(0,touchViewPoint.y,mainboxView.frame.size.width,0.5);

       CGRect oneFrame =movelineone.frame;

        oneFrame.size =CGSizeMake(60,73);

       xxView.frame = oneFrame;

       CGRect towFrame =movelinetwo.frame;

        towFrame.size =CGSizeMake(36,12);

       movelinetwoLable.frame = towFrame;

        

        movelineone.hidden =NO;

        movelinetwo.hidden =NO;

       xxView.hidden =NO;

        movelinetwoLable.hidden =NO;

        [selfisKPointWithPoint:touchViewPoint];//一点击就显示十字状态

    }


    -(void)start{

        [selfdrawBox];

        thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(drawLine)object:nil];

        [threadstart];

    }


    #pragma mark 画框框和平均线

    -(void)drawBox{

        // 画个k线图的框框

       if (mainboxView==nil) {

            mainboxView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,315,130)];

            mainboxView.layer.borderColor = [UIColorcolorWithHexString:@"#444444"withAlpha:0.5].CGColor;

            mainboxView.layer.borderWidth =0.5;

            mainboxView.userInteractionEnabled =YES;

            [selfaddSubview:mainboxView];

            //添加手指捏合手势,放大或缩小k线图

           pinchGesture = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(touchBoxAction:)];

            [mainboxViewaddGestureRecognizer:pinchGesture];

            UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizeralloc]init];

            [longPressGestureRecognizeraddTarget:selfaction:@selector(gestureRecognizerHandle:)];

            [longPressGestureRecognizersetMinimumPressDuration:0.3f];

            [longPressGestureRecognizersetAllowableMovement:36.0];

            [selfaddGestureRecognizer:longPressGestureRecognizer];

        }

        

       if (!isUpdate) {

            // k线图分割线

           CGFloat padRealValue =mainboxView.frame.size.height /4;

           for (int i =0; i<4; i++) {

               CGFloat y =mainboxView.frame.size.height-padRealValue * i;

               lines *line = [[linesalloc]initWithFrame:CGRectMake(0,0,mainboxView.frame.size.width,mainboxView.frame.size.height)];

                line.color =@"#999999";

                line.alpha =0.5;

                line.startPoint =CGPointMake(0, y);

                line.endPoint =CGPointMake(mainboxView.frame.size.width, y);

                [mainboxViewaddSubview:line];

            }

        }

        

        //显示开始日期控件

        if (startDateLab==nil) {

            startDateLab = [[UILabelalloc]initWithFrame:CGRectMake(1

                                                                     ,131

                                                                     ,50,8)];

           startDateLab.font = [UIFontsystemFontOfSize:8];

           startDateLab.text =@"--";

           startDateLab.textColor = [UIColorgrayColor];

            startDateLab.backgroundColor = [UIColorclearColor];

            [mainboxViewaddSubview:startDateLab];

        }

        

        //显示结束日期控件

       if (endDateLab==nil) {

            endDateLab = [[UILabelalloc]initWithFrame:CGRectMake(270

                                                                   ,131

                                                                   ,50,8)];

           endDateLab.font = [UIFontsystemFontOfSize:8];

           endDateLab.text =@"--";

           endDateLab.textColor = [UIColorgrayColor];

            endDateLab.backgroundColor = [UIColorclearColor];

            [mainboxViewaddSubview:endDateLab];

        }

        

        // MA5 均线价格显示控件

       if (MA5==nil) {

           MA5 = [[UILabelalloc]initWithFrame:CGRectMake(100, -8,30,8)];

            MA5.backgroundColor = [UIColorclearColor];

           MA5.font = [UIFontsystemFontOfSize:8];

           MA5.text =@"MA5";

            MA5.textColor = [UIColorcolorWithHexString:@"#d83dd9"withAlpha:1];

            [MA5sizeToFit];

            [selfaddSubview:MA5];

        }

        

        

        // MA10 均线价格显示控件

       if (MA10==nil) {

           MA10 = [[UILabelalloc]initWithFrame:CGRectMake(MA5.frame.origin.x +MA5.frame.size.width +10, -8,30,8)];

            MA10.backgroundColor = [UIColorclearColor];

           MA10.font = [UIFontsystemFontOfSize:8];

           MA10.text =@"MA10";

            MA10.textColor = [UIColorcolorWithHexString:@"#ebac31"withAlpha:1];

            [MA10sizeToFit];

            [selfaddSubview:MA10];

        }

        

        

        // MA20 均线价格显示控件

       if (MA20==nil) {

           MA20 = [[UILabelalloc]initWithFrame:CGRectMake(MA10.frame.origin.x +MA10.frame.size.width +10, -8,30,8)];

            MA20.backgroundColor = [UIColorclearColor];

           MA20.font = [UIFontsystemFontOfSize:8];

           MA20.text =@"MA20";

            MA20.textColor = [UIColorcolorWithHexString:@"#2e87e2"withAlpha:1];

            [MA20sizeToFit];

            [selfaddSubview:MA20];

        }


        //画个成交量的框框

        if (bottomBoxView==nil) {

            bottomBoxView = [[UIViewalloc]initWithFrame:CGRectMake(0,140,315,75)];

            bottomBoxView.layer.borderColor = [UIColorcolorWithHexString:@"#444444"withAlpha:0.5].CGColor;

            bottomBoxView.layer.borderWidth =0.5;

            bottomBoxView.userInteractionEnabled =YES;

            [mainboxViewaddSubview:bottomBoxView];

        }

        

       if (!isUpdate) {

            // 成交量分割线

           CGFloat padRealValue =bottomBoxView.frame.size.height /3;

           for (int i =0; i<3; i++) {

               CGFloat y =bottomBoxView.frame.size.height-padRealValue * i;

               lines *line = [[linesalloc]initWithFrame:CGRectMake(0,0,bottomBoxView.frame.size.width,bottomBoxView.frame.size.height)];

                line.color =@"#999999";

                line.alpha =0.5;

                line.startPoint =CGPointMake(0, y);

                line.endPoint =CGPointMake(bottomBoxView.frame.size.width, y);

                [bottomBoxViewaddSubview:line];

            }

        }

        

       //1

        shou1 = [[UILabelalloc]initWithFrame:CGRectMake(1,141,50,8)];

       shou1.text =@"7.5";

        shou1.font = [UIFontsystemFontOfSize:8];

        [shou1setTextColor:[UIColorgrayColor]];

        [selfaddSubview:shou1];

        

       //2

        shou2 = [[UILabelalloc]initWithFrame:CGRectMake(1,166,50,8)];

       shou2.text =@"5";

        shou2.font = [UIFontsystemFontOfSize:8];

        [shou2setTextColor:[UIColorgrayColor]];

        [selfaddSubview:shou2];

        

       //3

        shou3 = [[UILabelalloc]initWithFrame:CGRectMake(1,191,50,8)];

       shou3.text =@"2.5";

        shou3.font = [UIFontsystemFontOfSize:8];

        [shou3setTextColor:[UIColorgrayColor]];

        [selfaddSubview:shou3];


    }


    #pragma mark k线

    -(void)drawLine{

        self.kCount =self.xWidth / (self.kLineWidth+self.kLinePadding) +1; // K线中实体的总数


       getdata = [[getDataalloc]init];

        getdata.kCount =self.kCount;

        

        [getdata changeRKData:_riKArry];

         self.data =getdata.data;

        

        // 开始画K线图

        [selfdrawBoxWithKline];

        

        //NSLog(@"处理得dddd");

        // 清除旧的k线

        if (lineOldArray.count>0 && isUpdate) {

           for (lines *lineinlineOldArray) {

                [lineremoveFromSuperview];

            }

        }

        lineOldArray =lineArray.copy;

        

        if (_finishUpdateBlock &&isPinch) {

            _finishUpdateBlock(self);

        }

        isUpdateFinish =YES;

        // 结束线程

        [threadcancel];

    }



    #pragma mark 在框框里画k线

    -(void)drawBoxWithKline{

        

        // 平均线

        CGFloat padValue = (getdata.maxValue -getdata.minValue) /4;

       CGFloat padRealValue =mainboxView.frame.size.height /4;

       for (int i =0; i<5; i++) {

           CGFloat y =mainboxView.frame.size.height-padRealValue * i;

           // lable

           UILabel *leftTag = [[UILabelalloc]initWithFrame:CGRectMake(0, y-30/2-3,38,30)];

            leftTag.text = [[NSStringalloc]initWithFormat:@"%.2f",padValue*i+getdata.minValue];

            leftTag.textColor = [UIColorgrayColor];

            leftTag.font =self.font;

            //[leftTag sizeToFit];

            [mainboxViewaddSubview:leftTag];

            [lineArrayaddObject:leftTag];

        }



        

        // 开始画连接均线

        [selfdrawMAWithIndex:7andColor:@"#d83dd9"];//MA5,黄色

        [selfdrawMAWithIndex:8andColor:@"#ebac31"];//MA10,蓝色

        [selfdrawMAWithIndex:9andColor:@"#2e87e2"];//MA20,蓝色


        

        // 开始画连K线

        // x轴从0框框的宽度 mainboxView.frame.size.width变化  y轴为每个间隔的连线,如,今天的点连接明天的点

       NSArray *ktempArray = [selfchangeKPointWithData:getdata.data];//换算成实际每天收盘价坐标数组

       lines *kline = [[linesalloc]initWithFrame:CGRectMake(0,0,mainboxView.frame.size.width,mainboxView.frame.size.height)];

        kline.points = ktempArray;

        kline.lineWidth =self.kLineWidth;

        kline.isK =YES;

        [mainboxViewaddSubview:kline];

        [lineArrayaddObject:kline];

        

        //在成交量视图左右下方显示开始和结束日期

        NSString *tempStr1 =[[getdata.dataobjectAtIndex:0]objectAtIndex:0];

        startDateLab.text = [NSStringstringWithFormat:@"%@-%@-%@",[tempStr1substringWithRange:NSMakeRange (0,4)],[tempStr1substringWithRange:NSMakeRange (4,2)],[tempStr1substringWithRange:NSMakeRange (6,2)]];

       NSString *tempStr2 = [[getdata.dataobjectAtIndex:getdata.data.count-1]objectAtIndex:0];

        endDateLab.text = [NSStringstringWithFormat:@"%@-%@-%@",[tempStr2substringWithRange:NSMakeRange (0,4)],[tempStr2substringWithRange:NSMakeRange (4,2)],[tempStr2substringWithRange:NSMakeRange (6,2)]];


        // 开始画连成交量

       NSArray *voltempArray = [selfchangeVolumePointWithData:getdata.data];//换算成实际成交量坐标数组

        //NSLog(@"voltempArray:%@",voltempArray);

       lines *volline = [[linesalloc]initWithFrame:CGRectMake(0,0,bottomBoxView.frame.size.width,bottomBoxView.frame.size.height)];

        volline.points = voltempArray;

        volline.lineWidth =self.kLineWidth;

        volline.isK =YES;

        volline.isVol =YES;

        [bottomBoxViewaddSubview:volline];

        shou1.text = [commondchangePrice:getdata.volMaxValue];

        shou2.text = [commondchangePrice:getdata.volMaxValue/3*2];

        shou3.text = [commondchangePrice:getdata.volMaxValue/3];

        [lineArrayaddObject:volline];

    }


    #pragma mark 画各种均线

    -(void)drawMAWithIndex:(int)index andColor:(NSString*)color{

       NSArray *tempArray = [selfchangePointWithData:getdata.dataandMA:index];// 换算成实际坐标数组

       lines *line = [[linesalloc]initWithFrame:CGRectMake(0,0,mainboxView.frame.size.width,mainboxView.frame.size.height)];

        line.color = color;

        line.points = tempArray;

        //NSLog(@"date:%d",_date());

        line.isK =NO;

        [mainboxViewaddSubview:line];

        [lineArrayaddObject:line];

    }


    #pragma mark 把股市数据换算成实际的点坐标数组

    -(NSArray*)changeKPointWithData:(NSArray*)data{

        NSMutableArray *tempArray = [[NSMutableArrayalloc]init];

       pointArray = [[NSMutableArrayalloc]init];

       CGFloat PointStartX =self.kLineWidth/2;//起始点坐标

        //NSLog(@"date:%@",data);

       for (NSArray *itemin data) {

            CGFloat heightvalue = [[itemobjectAtIndex:2]floatValue];// 得到最高价

           CGFloat lowvalue = [[itemobjectAtIndex:3]floatValue];// 得到最低价

           CGFloat openvalue = [[itemobjectAtIndex:1]floatValue];// 得到开盘价

           CGFloat closevalue = [[itemobjectAtIndex:4]floatValue];// 得到收盘价

            CGFloat yHeight =getdata.maxValue -getdata.minValue ;// y的价格高度

           CGFloat yViewHeight =mainboxView.frame.size.height ;// y的实际像素高度

            // 换算成实际的坐标

           CGFloat heightPointY = yViewHeight * (1 - (heightvalue -getdata.minValue) / yHeight);

           CGPoint heightPoint = CGPointMake(PointStartX, heightPointY); // 最高价换算为实际坐标值

           CGFloat lowPointY = yViewHeight * (1 - (lowvalue -getdata.minValue) / yHeight);;

           CGPoint lowPoint = CGPointMake(PointStartX, lowPointY); // 最低价换算为实际坐标值

           CGFloat openPointY = yViewHeight * (1 - (openvalue -getdata.minValue) / yHeight);;

           CGPoint openPoint = CGPointMake(PointStartX, openPointY); // 开盘价换算为实际坐标值

           CGFloat closePointY = yViewHeight * (1 - (closevalue -getdata.minValue) / yHeight);;

           CGPoint closePoint = CGPointMake(PointStartX, closePointY); // 收盘价换算为实际坐标值

            // 实际坐标组装为数组

           NSArray *currentArray = [[NSArrayalloc]initWithObjects:

                                    NSStringFromCGPoint(heightPoint),

                                    NSStringFromCGPoint(lowPoint),

                                    NSStringFromCGPoint(openPoint),

                                    NSStringFromCGPoint(closePoint),

                                     [itemobjectAtIndex:0],//保存日期时间

                                     [itemobjectAtIndex:4],//收盘价

                                     [itemobjectAtIndex:7],// MA5

                                     [itemobjectAtIndex:8],// MA10

                                     [itemobjectAtIndex:9],// MA20

                                     [itemobjectAtIndex:2],//最高价

                                     [itemobjectAtIndex:3],//最低价

                                     [itemobjectAtIndex:1],//开盘价

                                     [itemobjectAtIndex:5],//成交量

                                     [itemobjectAtIndex:6],//成交金额

                                     

                                    nil];

            [tempArrayaddObject:currentArray];// 把坐标添加进新数组

            currentArray =Nil;

            PointStartX +=self.kLineWidth+self.kLinePadding;//生成下一个点的x

            

        }

       pointArray = tempArray;

       return tempArray;

    }


    #pragma mark 把股市数据换算成实际的点坐标数组 

    -(NSArray*)changePointWithData:(NSArray*)data  andMA:(int)MAIndex{

        NSMutableArray *tempArray = [[NSMutableArrayalloc]init];

       CGFloat PointStartX =0.0f; // 起始点坐标

       for (NSArray *itemin data) {

           CGFloat currentValue = [[itemobjectAtIndex:MAIndex] floatValue];//得到均价价格

            // 换算成实际的坐标

           CGFloat currentPointY =mainboxView.frame.size.height - ((currentValue -getdata.minValue) / (getdata.maxValue -getdata.minValue) *mainboxView.frame.size.height);

           CGPoint currentPoint = CGPointMake(PointStartX, currentPointY); // 换算到当前的坐标值

            [tempArrayaddObject:NSStringFromCGPoint(currentPoint)];//把坐标添加进新数组

            PointStartX +=self.kLineWidth+self.kLinePadding;//生成下一个点的x

        }

       return tempArray;

    }


    #pragma mark 把股市数据换算成成交量的实际坐标数组

    -(NSArray*)changeVolumePointWithData:(NSArray*)data{

        NSMutableArray *tempArray = [[NSMutableArrayalloc]init];

       CGFloat PointStartX =self.kLineWidth/2;//起始点坐标

       for (NSArray *itemin data) {

           CGFloat volumevalue = [[itemobjectAtIndex:5]floatValue];// 得到每份成交量

            CGFloat yHeight =getdata.volMaxValue -getdata.volMinValue ;// y的价格高度

           CGFloat yViewHeight =bottomBoxView.frame.size.height ;// y的实际像素高度

            // 换算成实际的坐标

           CGFloat volumePointY = yViewHeight * (1 - (volumevalue -getdata.volMinValue) / yHeight);

           CGPoint volumePoint = CGPointMake(PointStartX, volumePointY); // 成交量换算为实际坐标值

           CGPoint volumePointStart =CGPointMake(PointStartX, yViewHeight);

            //把开盘价收盘价放进去好计算实体的颜色

           CGFloat openvalue = [[itemobjectAtIndex:1]floatValue];// 得到开盘价

           CGFloat closevalue = [[itemobjectAtIndex:4]floatValue];// 得到收盘价

           CGPoint openPoint = CGPointMake(PointStartX, closevalue); // 开盘价换算为实际坐标值

           CGPoint closePoint = CGPointMake(PointStartX, openvalue); // 收盘价换算为实际坐标值

            

            

            // 实际坐标组装为数组

           NSArray *currentArray = [[NSArrayalloc]initWithObjects:

                                    NSStringFromCGPoint(volumePointStart),

                                    NSStringFromCGPoint(volumePoint),

                                    NSStringFromCGPoint(openPoint),

                                    NSStringFromCGPoint(closePoint),

                                    nil];

            [tempArrayaddObject:currentArray];// 把坐标添加进新数组

            currentArray =Nil;

            PointStartX +=self.kLineWidth+self.kLinePadding;//生成下一个点的x

            

        }

       // NSLog(@"处理完成");

        

       return tempArray;

    }


    #pragma mark 手指捏合动作

    -(void)touchBoxAction:(UIPinchGestureRecognizer*)pGesture{

       isPinch  =NO;

        //NSLog(@"状态:%li==%f",(long)pinchGesture.state,pGesture.scale);

       if (pGesture.state==2 &&isUpdateFinish) {

           if (pGesture.scale>1) {

               //放大手势

               self.kLineWidth ++;

                [selfupdateSelf];

            }else{

               //缩小手势

               self.kLineWidth --;

                [selfupdateSelf];

            }

        }

       if (pGesture.state==3) {

            isUpdateFinish =YES;

        }

    }

     //缩小手势,放大手势

    -(void)updateSelf{

        if (isUpdateFinish) {

           if (self.kLineWidth>20)

               self.kLineWidth =20;

           if (self.kLineWidth<1)

               self.kLineWidth =1;

            isUpdateFinish =NO;

           isUpdate =YES;

           self.data =nil;

           pointArray =nil;

           if (!thread.isCancelled) {

                [threadcancel];

            }

            self.clearsContextBeforeDrawing =YES;

            [threadcancel];

           thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(drawLine)object:nil];

            [threadstart];

            

        }

    }


    #pragma mark 长按就开始生成十字线

    -(void)gestureRecognizerHandle:(UILongPressGestureRecognizer*)longResture{

       isPinch =YES;

        //NSLog(@"gestureRecognizerHandle%li",(long)longResture.state);

        touchViewPoint = [longResturelocationInView:mainboxView];

        //手指长按开始时更新一般

        if(longResture.state ==UIGestureRecognizerStateBegan){

            [selfupdate];

        }

        //手指移动时候开始显示十字线

        if (longResture.state ==UIGestureRecognizerStateChanged) {

            [selfisKPointWithPoint:touchViewPoint];

        }

        

        //手指离开的时候移除十字线

        if (longResture.state ==UIGestureRecognizerStateEnded) {

            [movelineoneremoveFromSuperview];

            [movelinetworemoveFromSuperview];

            [xxViewremoveFromSuperview];

            [movelinetwoLableremoveFromSuperview];

            

           movelineone =nil;

           movelinetwo =nil;

           xxView =nil;

            movelinetwoLable =nil;

           isPinch =NO;

        }

    }


    #pragma mark 判断并在十字线上显示提示信息

    -(void)isKPointWithPoint:(CGPoint)point{

       CGFloat itemPointX =0;

       for (NSArray *iteminpointArray) {

            //NSLog(@"item:%@",item);


           CGPoint itemPoint =CGPointFromString([item objectAtIndex:0]); //收盘价的坐标

            itemPointX = itemPoint.x;

           int itemX = (int)itemPointX;

           int pointX = (int)point.x;

           if (itemX==pointX || point.x-itemX<=self.kLineWidth/2) {

                movelineone.frame =CGRectMake(itemPointX,movelineone.frame.origin.y,movelineone.frame.size.width,movelineone.frame.size.height);

                movelinetwo.frame =CGRectMake(movelinetwo.frame.origin.x,itemPoint.y,movelinetwo.frame.size.width,movelinetwo.frame.size.height);

               //垂直提示成交价格

               NSString *tempStr =[itemobjectAtIndex:4];

                riqLable.text = [NSStringstringWithFormat:@"%@-%@-%@",[tempStrsubstringWithRange:NSMakeRange (0,4)],[tempStrsubstringWithRange:NSMakeRange (4,2)],[tempStrsubstringWithRange:NSMakeRange (6,2)]];//日期

               kpLable.text =[NSStringstringWithFormat:@"开盘:%@",[itemobjectAtIndex:11]];

               zgLable.text =[NSStringstringWithFormat:@"最高:%@",[itemobjectAtIndex:9]];

               zdLable.text =[NSStringstringWithFormat:@"最低:%@",[itemobjectAtIndex:10]];

               spLable.text =[NSStringstringWithFormat:@"收盘:%@",[itemobjectAtIndex:5]];

                cjlLable.text =[NSStringstringWithFormat:@"成交量:%@",[commondchangePrice:[[itemobjectAtIndex:12]floatValue]]];

                cjeLable.text =[NSStringstringWithFormat:@"成交额:%@",[commondchangePrice:[[itemobjectAtIndex:13]floatValue]]];

                zflLable.text =[NSStringstringWithFormat:@"涨幅:%.2f%%",([[itemobjectAtIndex:5]floatValue]-[[itemobjectAtIndex:11]floatValue])/[[itemobjectAtIndex:11]floatValue]*100];

               CGFloat oneLableY =bottomBoxView.frame.origin.y;

               CGFloat oneLableX =0;

               if (itemPointX<xxView.frame.size.width/2) {

                    oneLableX =xxView.frame.size.width/2 - itemPointX;

                }

               if ((mainboxView.frame.size.width - itemPointX)<xxView.frame.size.width/2) {

                    oneLableX = -(xxView.frame.size.width/2 - (mainboxView.frame.size.width - itemPointX));

                }

               xxView.frame =CGRectMake(itemPointX -xxView.frame.size.width/2 + oneLableX, oneLableY,

                                                   xxView.frame.size.width,xxView.frame.size.height);

                

                 //NSLog(@"item:%@",item);

               //横向提示成交数量

               movelinetwoLable.text = [itemobjectAtIndex:5];//

               CGFloat twoLableX =movelinetwoLable.frame.origin.x;

                //如果滑动到了左半边则提示向右跳转

               if ((mainboxView.frame.size.width - itemPointX) >mainboxView.frame.size.width/2) {

                    twoLableX =mainboxView.frame.size.width -movelinetwoLable.frame.size.width;

                }else{

                    twoLableX =0;

                }

               movelinetwoLable.frame =CGRectMake(twoLableX,itemPoint.y -movelinetwoLable.frame.size.height/2 ,

                                                   movelinetwoLable.frame.size.width,movelinetwoLable.frame.size.height);

                

             

               break;

            }

        }

        

    }


    -(void)update{

        if (self.kLineWidth>20)

           self.kLineWidth =20;

        if (self.kLineWidth<1)

           self.kLineWidth =1;

       isUpdate =YES;

       if (!thread.isCancelled) {

            [threadcancel];

        }

        self.clearsContextBeforeDrawing =YES;


        [threadcancel];

        thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(drawLine)object:nil];

        [threadstart];

        

    }



    -(void)dealloc{

       thread =nil;

    }


    @end


    #import <Foundation/Foundation.h>


    @interface getData :NSObject

    @property (nonatomic,retain)NSMutableArray *data;

    @property (nonatomic,retain)NSArray *dayDatas;

    @property (nonatomic,retain)NSMutableArray *category;

    @property (nonatomic,retain)NSString *lastTime;

    @property (nonatomic,retain)UILabel *status;

    @property (nonatomic,assign)BOOL isFinish;

    @property (nonatomic,assign)CGFloat maxValue;

    @property (nonatomic,assign)CGFloat minValue;

    @property (nonatomic,assign)CGFloat volMaxValue;

    @property (nonatomic,assign)CGFloat volMinValue;

    @property (nonatomic,assign)NSInteger kCount;

    @property (nonatomic,retain)NSString *req_type;



    -(void)changeFSData:(NSArray*)lines;

    -(void)changeRKData:(NSArray*)lines;


    @end


    #import "getData.h"

    #import "commond.h"


    @implementation getData


    -(id)init{

       self = [superinit];

       if (self){

           self.isFinish =NO;

           self.maxValue =0;

           self.minValue =CGFLOAT_MAX;

           self.volMaxValue =0;

           self.volMinValue =CGFLOAT_MAX;

        }

        return  self;

    }


    //解析具体数据并赋值组合

    -(void)changeFSData:(NSArray*)lines{

        NSMutableArray *data =[[NSMutableArrayalloc]init];

    //NSMutableArray *category =[[NSMutableArray alloc] init];

       NSArray *newArray = lines;

        newArray = [newArrayobjectsAtIndexes:[[NSIndexSetalloc]initWithIndexesInRange:NSMakeRange(0,self.kCount>=newArray.count?newArray.count:self.kCount)]];//只要前面指定的数据

       

       NSInteger idx;


       for (idx =0; idx < newArray.count; idx++) {

            

           if (idx >0)

            {

               NSString *bfLine = [newArrayobjectAtIndex:idx-1];//前面一个数组

               NSString *line = [newArrayobjectAtIndex:idx];

               if([lineisEqualToString:@""]){

                   continue;

                }

                NSArray   *bfArr = [bfLinecomponentsSeparatedByCharactersInSet:[NSCharacterSetcharacterSetWithCharactersInString:@","]];

                NSArray   *arr = [linecomponentsSeparatedByCharactersInSet:[NSCharacterSetcharacterSetWithCharactersInString:@","]];

                

                // 收盘价的最小值和最大值

               if ([[arrobjectAtIndex:1]floatValue]>self.maxValue) {

                   self.maxValue = [[arrobjectAtIndex:1]floatValue];

                }

               if ([[arrobjectAtIndex:1]floatValue]<self.minValue) {

                   self.minValue = [[arrobjectAtIndex:1]floatValue];

                }

                

               float crtVol = [[arrobjectAtIndex:2]floatValue] - [[bfArr objectAtIndex:2]floatValue];//当前累加的数据减去上一个得到成交量

                 //NSLog(@"crtVol:%.2f",crtVol);

                // 成交量的最大值最小值

               if (crtVol>self.volMaxValue) {

                   self.volMaxValue = crtVol;

                }

               if (crtVol<self.volMinValue) {

                   self.volMinValue = crtVol;

                }

                NSMutableArray *item =[[NSMutableArrayalloc]init];

                

                [itemaddObject:[arrobjectAtIndex:0]];//成交均价

                [itemaddObject:[arrobjectAtIndex:1]];//成交价格

                [itemaddObject:[NSStringstringWithFormat:@"%.0f",crtVol]];//成交数量

                [itemaddObject:[arrobjectAtIndex:3]];//成交金额

                

                [dataaddObject:item];//组合总data

     

            }

           else{

               NSString *line = [newArrayobjectAtIndex:idx];

               if([lineisEqualToString:@""]){

                   continue;

                }

                NSArray   *arr = [linecomponentsSeparatedByCharactersInSet:[NSCharacterSetcharacterSetWithCharactersInString:@","]];

                // 收盘价的最小值和最大值

               if ([[arrobjectAtIndex:1]floatValue]>self.maxValue) {

                   self.maxValue = [[arrobjectAtIndex:1]floatValue];

                }

               if ([[arrobjectAtIndex:1]floatValue]<self.minValue) {

                   self.minValue = [[arrobjectAtIndex:1]floatValue];

                }

                // 成交量的最大值最小值

               if ([[arrobjectAtIndex:2]floatValue]>self.volMaxValue) {

                   self.volMaxValue = [[arrobjectAtIndex:2]floatValue];

                    //NSLog(@"volMaxValue:%f",self.volMaxValue);

                }

               if ([[arrobjectAtIndex:2]floatValue]<self.volMinValue) {

                   self.volMinValue = [[arrobjectAtIndex:2]floatValue];

                    //NSLog(@"volMinValue:%f",self.volMinValue);

                }

                NSMutableArray *item =[[NSMutableArrayalloc]init];

                

                [itemaddObject:[arrobjectAtIndex:0]];//成交均价

                [itemaddObject:[arrobjectAtIndex:1]];//成交价格

                [itemaddObject:[arrobjectAtIndex:2]];//成交数量

                [itemaddObject:[arrobjectAtIndex:3]];//成交金额

                

                

                [dataaddObject:item];//组合总data

                

                //NSLog(@"self.volMaxValue:%.2f",self.volMaxValue);


            }

            

        }

        

        

         //NSLog(@"data:%@",data);

    if(data.count==0){

    self.status.text = @"Error!";

       return;

    }

        

       self.data = data;

    }


    -(void)changeRKData:(NSArray*)lines{

        NSMutableArray *data =[[NSMutableArrayalloc]init];

       NSArray *newArray = lines;

        newArray = [newArrayobjectsAtIndexes:[[NSIndexSetalloc]initWithIndexesInRange:NSMakeRange(0,self.kCount>=newArray.count?newArray.count:self.kCount)]];//只要前面指定的数据

        

       NSInteger idx;

       int MA5=5,MA10=10,MA20=20;//均线统计

       for (idx = newArray.count-1; idx >=0; idx--) {

            

           NSString *line = [newArrayobjectAtIndex:idx];

           if([lineisEqualToString:@""]){

               continue;

            }

            NSArray   *arr = [linecomponentsSeparatedByCharactersInSet:[NSCharacterSetcharacterSetWithCharactersInString:@","]];

            // 收盘价的最小值和最大值

           if ([[arrobjectAtIndex:4]floatValue]>self.maxValue) {

               self.maxValue = [[arrobjectAtIndex:4]floatValue];

            }

           if ([[arrobjectAtIndex:4]floatValue]<self.minValue) {

               self.minValue = [[arrobjectAtIndex:4]floatValue];

            }

            // 成交量的最大值最小值

           if ([[arrobjectAtIndex:5]floatValue]>self.volMaxValue) {

               self.volMaxValue = [[arrobjectAtIndex:5]floatValue];

                //NSLog(@"volMaxValue:%f",self.volMaxValue);

            }

           if ([[arrobjectAtIndex:5]floatValue]<self.volMinValue) {

               self.volMinValue = [[arrobjectAtIndex:5]floatValue];

                //NSLog(@"volMinValue:%f",self.volMinValue);

            }

            NSMutableArray *item =[[NSMutableArrayalloc]init];

            

            [itemaddObject:[arrobjectAtIndex:0]];//日期

            [itemaddObject:[arrobjectAtIndex:1]];//今日开盘

            [itemaddObject:[arrobjectAtIndex:2]];//最高成交

            [itemaddObject:[arrobjectAtIndex:3]];//最低成交

            [itemaddObject:[arrobjectAtIndex:4]];//最近成交

            [itemaddObject:[arrobjectAtIndex:5]];//成交数量

            [itemaddObject:[arrobjectAtIndex:6]];//成交金额

            

           CGFloat idxLocation = [linesindexOfObject:line];

           // MA5

            [itemaddObject:[NSNumbernumberWithFloat:[selfsumArrayWithData:linesandRange:NSMakeRange(idxLocation, MA5)]]];//前五日收盘价平均值

           // MA10

            [itemaddObject:[NSNumbernumberWithFloat:[selfsumArrayWithData:linesandRange:NSMakeRange(idxLocation, MA10)]]];//前十日收盘价平均值

           // MA20

            [itemaddObject:[NSNumbernumberWithFloat:[selfsumArrayWithData:linesandRange:NSMakeRange(idxLocation, MA20)]]];//前二十日收盘价平均值

            

            [dataaddObject:item];//组合总data

            

        }

        //NSLog(@"data:%@",data);

       if(data.count==0){

           self.status.text =@"Error!";

           return;

        }

        

       self.data = data;

    }



    -(CGFloat)sumArrayWithData:(NSArray*)data andRange:(NSRange)range{

       CGFloat value =0;

       if (data.count - range.location>range.length) {

            NSArray *newArray = [dataobjectsAtIndexes:[[NSIndexSetalloc]initWithIndexesInRange:range]];

           for (NSString *itemin newArray) {

                NSArray *arr = [itemcomponentsSeparatedByCharactersInSet:[NSCharacterSetcharacterSetWithCharactersInString:@","]];

                value += [[arrobjectAtIndex:4]floatValue];//最近成交

            }

           if (value>0) {

                value = value/ newArray.count;

            }

        }

       return value;

    }


    @end


    实现效果如图:




    尊重知识,赞赏199元,并留下邮箱,将发整个源码,你的支持是我的动力。


    展开全文
  • 这是以雪球APP为原型,基于iOSK线开源项目。 该项目整体设计思路已经经过某成熟证券APP的商业认证。 本项目将K线业务代码尽可能缩减,保留核心功能,可流畅、高效实现手势交互。 K线难点在于手势交互和数据动态...
  • iOS 绘制股票K线图 2017-09-03 23:38:52
     k线图:有最新价、收盘价、开盘价、最高价、最低价、均价、卖量、买量等等。而我们需要展示给用户看的第一眼就是把它们全部绘制为k线图,直观。还有部分要转化为数值直接推动;  蜡烛:需要用到收盘价、开盘价...
  • ios股票K线图的绘制 2017-12-14 11:00:59
    前言:因为工作需要,要绘制一个股票K线图,因为自己不炒股,所以对股票知识很是有限,当时也想在网上找个demo直接拿来用的,但是找了很多都不合适,后来查了些资料,也看了很多别人的demo,打算自己写,此文针对...
  • 上篇文章中,我们了解了走势图k线图绘制及的一些关键点,基于大家都懂期货股票这些东西的基础上去讲解的,说的也不够全面,这篇文章我们以实战为主,一步一步写出可以商业化的k线图。 一、什么是k线图? 1.k线图:...
  • iOS 股票K线图、分时图 2018-07-14 15:52:04
    iOS 股票K线图、分时图,基本上翻遍了开源的项目,要不就是只分享了分时图没有k线纯粹一个噱头,要不就是有K线的性能叫人捉急,干脆自己写一套,分享出来。 前言:观察了市面上排名前十的金融类APP,唯雪球的K线交互...
  • k线系列目录 查看目录请点击这儿 补充知识K线虽然看上去复杂,但仔细观察就会知道几乎所有的k线无非由以下几种组成:(1)蜡烛(2)OHLC(3)线段(4)带状(5)圆形除此之外还有其他的,都是比较少见的。蜡烛绘制...
  • iOS Swift K线图,适用于股票和区块链Appgithub示例图 iOS Swift K线图,适用于股票和区块链App。Swift5.0编写,数据处理能力优秀。Demo集成websocket,并接入币安数据。 基于CHKLineChart二次开发,优化了性能和...
  • 前言:现在做金融的越来越多了,在很多的技术群中都有人问到k线图怎么去做,有没有相关的框架?两年前,我刚入这金融公司也是走这条路,但是发现网上的框架不多,干脆就自己搞一个出来。没人分享相关知识,就分享下...
  • 因为是刚转IOS不久,缺乏IOS的项目经验,所以在很多面试中都应聘不到好岗位,不料同学的一个公司招人,但需要做出某种功能,于是乎我迷上了画股票K线图,没想到两三天时间就搞定了,顺利拿下了offer,当然只是相对于...
  • k线系列目录 查看目录请点击这儿 前言当写完了所有需要使用的素材类后,我们开始搭建一个比较完整的K线Demo。它包含以下功能: 1、可以展示蜡烛 2、可以展示OHLC 3、可以左右滑动 4、可以长按出现十字叉...
  • iOS 股票走势图(分时图,K线图)--- 在绘制虚实线,走势图背景时使用了更简洁的方法,理解其中的实现原理按照自己的思路封装收获更多----共同学习,欢迎提出宝贵的意见和更好的方法
  • 最近项目中遇到了需要获取网站上的数据,然后以折线图的方式表示出来的需求。于是发现了swift下非常强大的图表库-# Charts ...这一篇我们来看一下有关k线图的实现。实现后的效果如下图所示: 未完待续 ...
  • k线图-ios源码 2020-06-06 23:30:53
    网上收集的几个制作k线图的app源码,股票k线图源代码,包括股票分析
  • iOS Objective-C 自定义K线图 2018-04-13 15:26:14
    前些天由于需求自定义了K线图,由于效果变更,现将此K线图记录一下。请先看效果图:自定义label KLineViewLabel.h:#import &lt;UIKit/UIKit.h&gt;@interface KLineViewLabel : UIView@property(nonatomic,...
  • 就股票软件开发而言 重中之重无非就是画制k线图了 本人画制过10多个软件的k线图 浅谈下画图的思路 为了保障图标的动态效果 只能采用滚动视图 1、首先得准备数据模型 知道自己需要绘制的k线图 什么指标 通过开高收...
  • k线系列目录 查看目录请点击这儿 接着上篇文章继续说。在上文中我们把蜡烛绘制完,也讲到在K线中常见的几种图形: 蜡烛 OHLC 线段 带状 圆形 那在这篇文章里,我们把其余的也绘制一下,争取做一个基础的类库,这样...
  • ios 股票曲线k线图源码demo 2020-06-14 23:30:28
    ios 股票曲线k线图源码demo , 仅供参考
1 2 3 4 5 ... 20
收藏数 8,134
精华内容 3,253