0

コア グラフィックスを使用してサイン チャートの作成に取り組んでいます。チャートを描くことだけですべてのことを行い、2点ジョイントに曲線を追加したいだけでうまくいきました。

私のチャートは下の画像のようになります。

グラフの例

下の画像のような線を描く必要がありますが、方法がわかりません:

生成したいチャート

誰でもこの問題で私を助けることができますか?

私のDrawRectコードは以下です

- (void)drawRect:(CGRect)rect
{
    [self setClearsContextBeforeDrawing: YES];

    CGContextRef context = UIGraphicsGetCurrentContext();


    CGColorRef backColorRef = [UIColor blackColor].CGColor;
    CGFloat backLineWidth = 2.f;
    CGFloat backMiterLimit = 0.f;

    CGContextSetLineWidth(context, backLineWidth);
    CGContextSetMiterLimit(context, backMiterLimit);

    CGContextSetShadowWithColor(context, CGSizeMake(3, 5), 8, backColorRef);

    CGContextSetLineJoin(context, kCGLineJoinRound);

    CGContextSetLineCap(context, kCGLineCapRound );

    CGContextSetBlendMode(context, kCGBlendModeNormal);

    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);



    int x = 320 ;
    int y = 180 ;

    for (int i=0; i<vDesc.count; i++)
    {

        CGPoint bPoint = CGPointMake(30, y);
        CGPoint ePoint = CGPointMake(x, y);

        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
        [label setCenter:CGPointMake(bPoint.x-15, bPoint.y-30)];
        [label setTextAlignment:UITextAlignmentCenter];
        [label setBackgroundColor:[UIColor clearColor]];
        [label setTextColor:[UIColor whiteColor]];
        [label setText:[vDesc objectAtIndex:i]];
        [self addSubview:label];

        CGContextMoveToPoint(context, bPoint.x, bPoint.y-30);
        CGContextAddLineToPoint(context, ePoint.x, ePoint.y-30);

        y -= 30;

    }
    NSLog(@"%d",hDesc.count);
    for (int i=0; i<hDesc.count; i++)
    {

        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i*vInterval+5, 150, 30, 30)];
        [label setTextAlignment:UITextAlignmentCenter];
        [label setBackgroundColor:[UIColor clearColor]];
        [label setTextColor:[UIColor whiteColor]];
        label.numberOfLines = 1;
        label.adjustsFontSizeToFitWidth = YES;
        label.minimumFontSize = 1.0f;
        [label setText:[hDesc objectAtIndex:i]];

        [self addSubview:label];
    }



    CGColorRef pointColorRef = [UIColor colorWithRed:24.0f/255.0f green:116.0f/255.0f blue:205.0f/255.0f alpha:1.0].CGColor;
    CGFloat pointLineWidth = 1.5f;
   // CGFloat pointMiterLimit = 5.0f;

    CGContextSetLineWidth(context, pointLineWidth);
   // CGContextSetMiterLimit(context, pointMiterLimit);


    CGContextSetShadowWithColor(context, CGSizeMake(3, 5), 8, pointColorRef);

    CGContextSetLineJoin(context, kCGLineJoinRound);

    CGContextSetLineCap(context, kCGLineCapRound );

    CGContextSetBlendMode(context, kCGBlendModeNormal);

    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);

    if (array1.count!=0)
    {
        CGPoint p1 = [[array1 objectAtIndex:0] CGPointValue];
        //int i = 1;
        CGContextMoveToPoint(context, p1.x, 380-p1.y);

//         CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400);
        for (int i=0; i<[array1 count]; i++)
        {
            p1 = [[array1 objectAtIndex:i] CGPointValue];
            CGPoint goPoint = CGPointMake(p1.x, 430-p1.y*vInterval/20);


            CGContextAddLineToPoint(context, goPoint.x, goPoint.y);
            UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];

            [bt setBackgroundColor:[UIColor redColor]];

            [bt setFrame:CGRectMake(0,0,3,3)];
            [bt setCenter:goPoint];
            [self addSubview:bt];
        }

    }
    else
    {
        NSLog(@"empty");
    }
    CGContextStrokePath(context);   

}
4

1 に答える 1