0
votes

In Core Plot, as the user scrolls, I am trying to move an annotation along the line of a scatter plot. I have data points at each hour, but would like to plot the annotation at more than just the hour marks. I'd like to get CGPoint information for interpolated data. For instance, I'd like to get the CGPoint for hour (index) 12.25.

I have been searching for ways to do this, but can't find one.

1
If I understand you correctly, you want a point between two points given a certain parameter(hour)? - dezinezync
Yep. I gave Y values for points at index 12 and 13, core plot then interpolated datapoints in between 12 and 13. I'd like to know what the interpolated Y value is at, say, 12.25. And I'd like to get a CGPoint from that, so I could create an annotation anchored there. - BigCheesy
Essentially, I want this method on CPTScatterPlot to accept a CGFloat -(CGPoint)plotAreaPointOfVisiblePointAtIndex:(NSUInteger)idx; - BigCheesy
Keep in mind what you are doing to the user by using a computed interpolation value. It's presented as ultimate value while it is rather an educated guess, so you are "lying" to the user (as Edward Tufte has explained it). As a general rule: keep the "lying factor" of your data display as low as possible. - Mike Lischke

1 Answers

0
votes

Linear Interpolation (Wikipedia link) is easy.

Given two points, (x1, y1) and (x2, y2), a point between them where a is a fraction between zero (0) and one (1), the interpolated point (x, y) is given by:

x = (1 - a) * x1 + a * x2
y = (1 - a) * y1 + a * y2

In the example given in the question, a would be 0.25.