0

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

Srivathsa
  • 606
  • 10
  • 34

1 Answers1

1

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

Jonathan Cichon
  • 4,396
  • 16
  • 19
  • Thanks for the quick answer. I have only 12 data points and i am writing 12 lines only. But why I am seeing 13th data point (which crossed my clipping area) and path went till the end of the view ? float dataLineCompare1[] = {0.76, 0.87, 0.89, 0.71, 0.64, 0.62, 0.67, 0.6, 0.67, 0.73, 0.73, 0.91}; – Srivathsa Nov 09 '12 at 09:24