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