Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top