Take the 2-minute tour ×

Thanks in advance. Is it possible to create a graph like this in iphone using Objective c. enter image description here

I have downloaded the core-plot Library from hg clone http://core-plot.googlecode.com/hg/ core-plot and try to do an example from the http://www.jaysonjc.com/programming/pie-chart-drawing-in-iphone-using-core-plot-library.html but i am unable to do even downloaded one also not building. It is giving the error that /Users/apple/Desktop/coreplotLibExamples/piechartsample/Classes/PieChart_SampleViewController.m:15:0 /Users/apple/Desktop/coreplotLibExamples/piechartsample/Classes/PieChart_SampleViewController.m:15: error: 'CPLayerHostingView' undeclared (first use in this function)

If any one have idea what is the problem, please help to do this.

share|improve this question
possible duplicate of Cocoa Graphing/Plotting Framework that Works on iPhoneOS –  Brad Larson Jul 30 '11 at 15:14

3 Answers 3

It depends on your needs. If you have a fixed number of categories on the y axis, then you could create three UIViews, of red, yellow and green colours, then set the width respectively. If you had a varying number of categories/scale, you're going to need to do quartz drawing, and might want to look into a graphing API such as core plot.

Anyhow, to do this with UIViews, your code would look something like this (for each item in the graph): (untested)...

#define kBarHeight 50 // Or however much you want

float graphWidth = 200; // Suppose you had 200 px across.    

int high = 3;
int emerging = 3;
int low = 6;

float total = high+emerging+low;
float oneSect = graphWidth/total;

redView.frame = CGRectMake(0,0,oneSect*high,kBarHeight);
yellowView.frame = CGRectMake(redView.frame.size.width,0,oneSect*emerging,kBarHeight);
greenView.frame = CGRectMake(redView.frame.size.width+yellowView.frame.size.width,0,oneSect*low,kBarHeight);
share|improve this answer

You can use Core Plot

share|improve this answer

For the above edited question , It is giving error because 'CPLayerHostingView' is for MAC. We need to Use 'CPTGraphHostingView' for iphone and in the viewDidLoad method .hostedGraph = graph;

share|improve this answer

Your Answer


