グラフを描いていますが、昇順の線を緑、降順の線を赤にします。私は次のことを試しました:
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;
}
しかし、それは機能していません。すべてが赤で表示されています。どうすればこれを修正できますか?