核心图 - 从x y值获取父视图的坐标

时间:2014-04-22 01:54:52

标签: ios ios7 core-plot

我有一个散点图和该图中一个点的x,y值。我想在情节的顶部添加信息,但我似乎无法从x y值获取父视图坐标。我从这个问题得到了以下代码,但值不正确:Core Plot: How to present popover from a bar selected by the user

我的CPTGraphHostingView *hostView;位于UIView *statsView;

NSDecimal plotPoint[2];
NSNumber *plotXvalue = [distanceArray objectAtIndex:index];

plotPoint[CPTCoordinateX] = plotXvalue.decimalValue;

NSNumber *plotYvalue = [altitudeArray objectAtIndex:index];
plotPoint[CPTCoordinateY] = plotYvalue.decimalValue;

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.hostView.hostedGraph.defaultPlotSpace;

// convert from data coordinates to plot area coordinates
CGPoint dataPoint = [plotSpace plotAreaViewPointForPlotPoint:plotPoint numberOfCoordinates:2];

// convert from plot area coordinates to graph (and hosting view) coordinates
dataPoint = [self.hostView.hostedGraph convertPoint:dataPoint   fromLayer:self.hostView.hostedGraph.plotAreaFrame.plotArea];


// convert from hosting view coordinates to self.view coordinates (if needed)
dataPoint = [statsView convertPoint:dataPoint fromView:self.hostView];

NSLog(@"barWasSelectedAtRecordIndex x: %@, y: %@", plotXvalue, plotYvalue);
NSLog(@"datapoint coordinates tapped: %@", NSStringFromCGPoint(dataPoint));

这是打印的日志

barWasSelectedAtRecordIndex x:2.002954100413836,y:797.5011302303315

数据点坐标被点击:{442.67648899476842,80323.113023033162}

更新:事实证明我在情节完全设置之前调用了这个,这是伪造数字的来源。不幸的是,在设置后调用仍然没有给我正确的答案。更接近但仍然错误。

数据点坐标点击:{109.55009099317836,187.9865691006616}

更新2 作为提示,我的X坐标与我期望的不成比例 图形值3,6,9,12,15给出坐标32,71,109,147,186

0 个答案:

没有答案