tags:

views:

20

answers:

0

Hi all,

I am doing an application for drawing a graph. I'm using following code to draw graph.

for (int j = 0;j < 5; j++) {
     UIGraphicsBeginImageContext(self.subView.frame.size);
     [subView.image drawInRect:CGRectMake(0, 0, self.subView.frame.size.width,
self.subView.frame.size.height)];
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,0.0,0.0,1.0);
     CGContextBeginPath(UIGraphicsGetCurrentContext());
     float xCord = graphStartX;
     float yCord = (graphStartY + graphHeight * j / 5);
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), xCord, yCord);
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), xCord - 10, yCord);
     CGContextStrokePath(UIGraphicsGetCurrentContext());
     subView.image = UIGraphicsGetImageFromCurrentImageContext();
}

Drawing a graph is working fine. I want to draw more than two graphs in the same graph view. That is also working fine. But the thing is I was not able to remove particular graph from the view.

For that what I'm doing is removing entire graph and redrawing all the graphs in a loop. by doing this application performance is decreasing.

I want an optimised solution for this.

Thanks in advance.