How to fix performance issues for lengthy graphs in drawRect for high resolution iOS devices?

My app has a lengthy graph to be displayed where the X-Axis is marked with years ranging from 400 to 2100. The graph is drawn in a UIView and added as sub view to a UIScrollView. The axis is drawn with year markers using CGContextRef in drawRect (Code pasted below).


Due to lengthy axis the width of graph's (UIView) frame is set to 10000. This graph is drawn without issues in medium screen resolution devices like iPad 2. However when this graph is opened in high resolution devices like iPad Air, issues like background not drawn (became transparent) and when scrolled the entire graph becomes messy due to contents redrawn without erasing previously drawn content.


Even I have called following methods in 'setFrame' delegate but no use.

[self setNeedsLayout];
[self setNeedsUpdateInRect:self.frame];


Can anyone suggest drawing graphics in drawRect in efficient way to handle performance for high resolution devices?


Following is my code in drawRect delegate:

CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];

CGPoint startPoint = CGPointMake(graphEndPadding, graphBaselineY);
CGContextMoveToPoint(context, startPoint.x, startPoint.y);

//Create line from starting point to end point
CGPoint endPoint = CGPointMake(graphLengthPixels+graphEndPadding, graphBaselineY);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);

//Create hashmark point system
CGFloat currX = startPoint.x;
CGFloat yVal = startPoint.y + graphHashMarkLength;

//Draw hashmarks
int count = 0;
while(currX <= endPoint.x) {
    //Draw hashmark
    CGContextMoveToPoint(context, currX, graphBaselineY);
    CGContextAddLineToPoint(context, currX, yVal);

    //Move to next hashmark
    currX += pixelYearIncrement;
    count++;
}

//Draw x-axis
CGContextSetLineWidth(context, 1);
CGContextSetLineCap(context, cgLineCapSquare);
CGContextSetRGBStrokeColor(context, 0.7765, 0.6118, 0.4275, 1.0);
CGContextStrokePath(context);