PDA

View Full Version : How to: Simple graph?




MTShipp
Jun 6, 2009, 10:14 PM
I am trying to figure out how to draw a simple trending graph. I do not need anything fancy. Just some whole number points over a short period of time. I have the 'Beginning iPhone Development' book but that is not shown in the chapters. Can someone tell me where to find info on that? If it is in the SDK, please tell me how to find it.



Niiro13
Jun 7, 2009, 02:24 AM
Unless I am mistaken, you'd have to draw the graphs yourself using Quartz 2D functions

Example:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 20.0f, 40.0f);
CGContextAddLineToPoint(context, 20.0f, 210.0f);
CGContextAddLineToPoint(context, 210.0f, 210.0f);
CGContextStrokePath(context);

That will get you the axis line for both the x and the y (yeah, a lot for just two lines >_<).

At least that's what I believe you have to do.

firewood
Jun 7, 2009, 07:30 PM
There's example graphing code in Apple's Accelerometer sample app, available on their dev site.