4

I would like to create a simple Line Graph like the following,

enter image description here

I googled to find out some sample and I got CorePlot which looks too heavy. Can anyone suggest me how to create a kind of line graph like below or tutorial is also most welcome. Please

Perseus
  • 1,546
  • 4
  • 30
  • 55
  • one of the possibilities is [here](http://blogs.remobjects.com/blogs/mh/2010/01/26/p973) – holex Jul 19 '12 at 09:57

2 Answers2

1

Well, first, why calling that graph simple? You can make it by drawing vertical lines along the X coordinate. You have (probably) an array with the top points (that show the weight progress), so you draw a line from a top point till the base line in a loop that will parse all your top points. Here is the code to draw a line, call it for each top point:

-(void)drawLineFromX:(CGPoint)topPoint{
    UIGraphicsBeginImageContext(instanceToYourImageView.image.size);
    [instanceToYourImageView.image drawInRect:CGRectMake(0, 0, instanceToYourImageView.image.size.width, instanceToYourImageView.image.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y + a_value_to_reach_the_base_line);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    [instanceToYourImageView setImage:UIGraphicsGetImageFromCurrentImageContext()];
    UIGraphicsEndImageContext();
}

Here the CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0); is black, but you can easily change it to the desired one.

Cheers!

John Smith
  • 2,012
  • 1
  • 21
  • 33
0

or you can use this https://github.com/pyanfield/WSChart

pyanfield
  • 479
  • 6
  • 19