Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top