Skip to content

Instantly share code, notes, and snippets.

@projectxcappe
Created August 29, 2011 20:14
Show Gist options
  • Save projectxcappe/1179271 to your computer and use it in GitHub Desktop.
Save projectxcappe/1179271 to your computer and use it in GitHub Desktop.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self.bgColor setFill];
NSUInteger count = [self.points count];
CGFloat prevValX;
CGFloat prevValY;
CGFloat deltaX = LENGTH / (count - 1);
CGFloat deltaY = HEIGHT / (count - 1) ;
//allocate data points for graph
for(int i=1; i<count; i++){
NSValue *currentPointValue = [self.points objectAtIndex:i];
CGPoint currentPoint = [currentPointValue CGPointValue];
CGPoint previousPoint = [[self.points objectAtIndex:i-1] CGPointValue];
prevValX = previousPoint.x;
prevValY = previousPoint.y;
//Scale the graph
CGFloat xVal = count + (deltaX * i);
CGFloat yVal = currentPoint.y + (deltaY * i) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment