Reputation: 4409
I'd like to be able to draw a graph using just the Apple Framework.
Is this possible using just CoreGraphics, or do I need to use any other framework?
I don't want to use any third party framework for drawing the graph.
Upvotes: 2
Views: 2193
Reputation: 119242
Yes, of course it is possible. A graph like that is just a line. You can use a UIBezierPath or CGPath to draw this. Typically you'd have an array of the points on your graph, then just add lines to each point when building your path.
WWDC 2011 session 129 goes through how the graph in the Stocks app is drawn and made "fancy", all using core graphics.
Upvotes: 6
Reputation: 978
This would be a sample code to do something with CoreGraphics
CGContextBeginPath(context);
CGContextMoveToPoint(context, startX, startY);
CGContextAddLineToPoint(context, nextX, nextY);
// [...] and so on, for all line segments
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] cgColor]);
CGContextStrokePath(context);
If you want to draw axis, labels, I suggest using CorePlot http://code.google.com/p/core-plot/
Upvotes: 1