7

Does anyone know of any existing code that will draw a graph for me in my iPhone application? I just need a simple line graph without labels or a title or even axis labels for the data.

Or does anyone have ideas about where to start so that I can learn how to draw such a thing? I've never dealt with actual graphics for the iPhone. All my applications are just image based until now.

Thanks!

STW
  • 44,917
  • 17
  • 105
  • 161
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
  • possible duplicate of [Cocoa Graphing/Plotting Framework that Works on iPhoneOS](http://stackoverflow.com/questions/263472/cocoa-graphing-plotting-framework-that-works-on-iphoneos) – Brad Larson Dec 30 '10 at 17:42

2 Answers2

10

Try out the Core Plot framework http://code.google.com/p/core-plot/

Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • It's a great framework but probably overkill if he just wants to draw lines without axes and labels. – Pascal Jan 01 '11 at 21:18
  • That's a good point. However, since Core Plot is open source, one may look at the code to figure out how to draw a line graph without the axes. – Jasarien Jan 02 '11 at 12:40
  • It's never overkill to use a library even for simple things - and it gives you more options later. It also gives you much nicer presentation off the bat. – Kendall Helmstetter Gelner Feb 11 '13 at 19:31
8

If you would attempt to draw yourself, you'd use the Path functions to draw in a context in Quartz

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);

There is a lot of sample code to deal with context and drawing in quartz.

But there are probably some libraries to facilitate drawing graphs... someone else would have to help you with those though, not my cup of tea :)

Pieter
  • 17,435
  • 8
  • 50
  • 89