开发者

How to create Graphs in iphone programmatically

Is it possible to create a graph like this in iphone using Objective-C.

How to create Graphs in iphone programmatically

I have downloaded the core-plot Library from hg clon开发者_运维知识库e 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)


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


You can use Core Plot


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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜