i'm drawing a graph and i want the the ascending lines to be in green and the descending lines in red. i tried the following:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGPoint previousPoint = CGPointMake(0.0, 0.0);
//graph the points
for (int i = 0; i < self.numberOfS; i++) {
CGPoint currentPoint = CGPointMake(150+(40*[[[self.grades objectAtIndex:i] s] doubleValue]), 59+(40*(i+1)));
if (previousPoint.x != 0.0f) {
if (previousPoint.x > currentPoint.x) {
CGContextMoveToPoint(context, previousPoint.x, previousPoint.y);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextAddLineToPoint(context, 150+(40*[[[self.grades objectAtIndex:i] semesterGPA] doubleValue]), 59+(40*(i+1)));
} else{
CGContextMoveToPoint(context, previousPoint.x, previousPoint.y);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextAddLineToPoint(context, 150+(40*[[[self.grades objectAtIndex:i] semesterGPA] doubleValue]), 59+(40*(i+1)));
}
}
previousPoint.x = currentPoint.x;
previousPoint.y = currentPoint.y;
}
but it's not working, everything is in red. how can i fix this ?