0

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)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sandy_ios
  • 669
  • 1
  • 11
  • 25
  • 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 Jul 30 '11 at 15:14

3 Answers3

1

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);
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
1

You can use Core Plot

iProgrammer
  • 3,099
  • 3
  • 33
  • 59
0

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;

Sandy_ios
  • 669
  • 1
  • 11
  • 25