0

I want to create a graph in my ipad which takes 3 to 4 inputs and then creates graph i have found solution using pie chart but i want simple graph with x-axis values and y-axis values.

4

1 回答 1

0

If you want to use a complex framework with lot of features, checkout : Core Plot.

In case you want simple Graph paper layout,

You will need to subclass UIView and override drawRect and make draw dotted lines using loops.

depending what how many vertical and horizontal lines you can accomodate.

Also for drawing the graph, pass an NSArray to the GraphView containing CGPoints wrapped by NSValue. loop through the points and convert them to physical coordinates of the View.

for this you will need to keep track of how many screen pixels does each x and y unit represent and then little bit of math will give you screen pixels of the GraphView.

Just join the Points by straight lines using Core Graphics functions.

CGContextMoveToPoint and CGContextAddlineToPoint.

You will need to use different CGPaths to draw different components of the view like Graph lines, axis lines and the graph itself.

But if you really need more complex tasks go for Core-Plot.

Checkout Core-Plot examples at :

http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application

于 2012-05-07T05:59:35.677 回答