Search code examples
iphonecgpathlinegraph

How to get point on the graph in iPhone Line graph


HI all,

I'm working on line graph. I'm able to draw line graph perfectly. But the thing is I want the effect like shown in the below image.

enter image description here

I want the slider effect. I'm storing the graph path using CGPath. If the slider moves on the graph according value has to display on the upper label..

Please help me.


Solution

  • You can't access the data from the CGPath. You need to hold your own data structure (an array or NSArray) with the (x,y) pairs. Then, figuring out what data point corresponds to a location on the screen is a matter of computing the inverse of the function you used to figure out the location on the screen of a data point.