質問

I am trying to draw a line graphs. I am able to draw the line graph but not able restrict the drawing area.

I want to draw the line graph from start to end position. But its coming beyond the drawing area. Could you please help me how to clip the area.

In Below image the line graph should stop where green dotten line is stopped.

Here is the code that I used..

    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, kOffsetX + kStepX, kGraphHeight - maxGraphHeight * dataLineCompare1[0]);
    for (int i = 1; i < sizeof(dataLineCompare1); i++)
    {
        CGContextAddLineToPoint(ctx, kOffsetX + ((i+1) * kStepX), kGraphHeight - maxGraphHeight * dataLineCompare1[i]);
    }
    CGContextDrawPath(ctx, kCGPathStroke);

enter image description here

役に立ちましたか?

解決

use CGContextClipToRect(ctx, yourDrawingArea) before drawing the lines.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top