我已經實現了下面的代碼在我CPTScatterPlotDelegate顯示標註泡沫CorePlot顯示標註:當選擇點是顛倒
-(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僅僅是一個自定義類握着我的數據和_annotation是實例我大喊。
問題是我不能讓標註位置正常工作。如果我設置_view到ViewController.view我得到正確的標註,但在錯誤的地方是這樣的:
如果我設置_view到CPTGraphHostingView,而不是我得到正確的點,但標註似乎是翻轉這樣的:
如何我得到正確的情節點座標來顯示標註?
感謝埃裏克是偉大的工作,我所用的方法:[圖convertPoint:touchedPoint toLayer:_view.layer]雖然。我猜想同樣的事情? – Imran
我正在使用這個 'CGPoint convertedPoint = [plot.graph convertPoint:touchedPoint toLayer:self.view.layer];' 它仍然有點點,坐在點的左邊... ...圖形填充會影響這個嗎? –