I have implemented the following code in my CPTScatterPlotDelegate to display a callout bubble:
-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)plot.plotSpace;
CPTGraph *graph = plot.graph;
int yIdent = ((NSString*)plot.identifier).intValue;
NSNumber *yVal = [[_dataRange yForIndex:index] objectAtIndex:yIdent-1];
NSNumber *xVal = [_dataRange xForIndex:index];
double doublePrecisionPlotPoint[2];//[x,y]
doublePrecisionPlotPoint[0] = xVal.doubleValue;
doublePrecisionPlotPoint[1] = yVal.doubleValue;
CGPoint touchedPoint = [graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:doublePrecisionPlotPoint];
if(_annotation)
[_annotation dismissCalloutAnimated:YES];
_annotation = [[SMCalloutView alloc] init];
//todo appropriate units
_annotation.title = [NSString stringWithFormat:@"%.2f kg", yVal.doubleValue];
[_annotation presentCalloutFromRect:CGRectMake(touchedPoint.x, touchedPoint.y, 1, 1) inView:_view constrainedToView:_view permittedArrowDirections:SMCalloutArrowDirectionAny animated:YES];
}
_dataRange is just a custom class holding my data and _annotation is the instance of my callout.
The problem is I cant't get the position of the callout working properly. If I set _view to the ViewController.view I get the right callout but in the wrong place like this:
If I set _view to the CPTGraphHostingView instead I get the right point but the callout appears to be flipped like this:
How to I get the right plot point co-ordinates to display the callout?