PDA

View Full Version : Graphing!




louden
Jul 16, 2008, 10:31 AM
Anyone know if there's anything in the SDK about how to draw a simple 2D graph? Kind of like the Stocks Applet uses?

Any push in the right direction would be greatly appreciated...



chrisesposito
Jul 16, 2008, 11:28 AM
Take a look at the Accelerometer Graph sample code.

davedelong
Jul 17, 2008, 09:22 AM
The basic idea is that it's an NSBezierPath that you add a whole bunch of points to like so:
NSBezierPath * myPath = [NSBezierPath bezierPath];
[myPath moveToPoint:NSMakePoint(0,0)]; //the starting point
[myPath lineToPoint:NSMakePoint(0,1)];
[myPath lineToPoint:NSMakePint(1,1)];
... etc...
[myPath stroke];
[myPath release];

louden
Jul 20, 2008, 09:52 PM
Anyone have sample code that mimics the stock application graphing? That's pretty clean...

GoCubsGo
Jul 20, 2008, 11:16 PM
Kinda off topic but I sure wish they'd bring out a graphing calculator like the TI ones. :D

Sbrocket
Jul 20, 2008, 11:55 PM
The basic idea is that it's an NSBezierPath that you add a whole bunch of points to like so:
NSBezierPath * myPath = [NSBezierPath bezierPath];
[myPath moveToPoint:NSMakePoint(0,0)]; //the starting point
[myPath lineToPoint:NSMakePoint(0,1)];
[myPath lineToPoint:NSMakePint(1,1)];
... etc...
[myPath stroke];
[myPath release];

NSBezierPath does not exist on the iPhone platform. I believe the way to do drawing like that is with CoreGraphics and a CGPath.