我在这个问题上被困了一段时间。我想要做的是得到图
来自-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point事件的数据。我不希望那个用户只能用-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index来触摸-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index。因此,我想要做的是触摸我的Scatter Plot上的任何地方--例如,在绘制的线之上,获取我在触摸事件下面的位置,然后在屏幕上绘制这个点。我见过这样的情况:Using core-plot, how can you convert a touched point to the plot space?,但不起作用。
编辑:,这是用于plotSymbol触摸的。我想触碰图表上的任何地方,并显示图表上的点。我不想碰那个情节符号,只想在那一点上展示我的价值。我想要能够触摸它之上或下方的绘制线在一个图表,它应该能够识别,有一个我的CGPoint)point的情节符号。
-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index{
CPTXYGraph *graph = (self.graphs)[0];
if ( symbolTextAnnotation ) {
[graph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
symbolTextAnnotation = nil;
}
// Setup a style for the annotation
CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
hitAnnotationTextStyle.color = [CPTColor whiteColor];
hitAnnotationTextStyle.fontSize = 16.0;
hitAnnotationTextStyle.fontName = @"Helvetica-Bold";
// Determine point of symbol in plot coordinates
NSDictionary *dataPoint = plotData[index];
NSNumber *x = dataPoint[@(CPTScatterPlotFieldX)];
NSNumber *y = dataPoint[@(CPTScatterPlotFieldY)];
NSArray *anchorPoint = @[x, y];
// Add annotation
// First make a string for the y value
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
NSString *yString = [formatter stringFromNumber:y];
// Now add the annotation to the plot area
CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle] ;
CPTImage *background = [CPTImage imageForPNGFile:@"check"];
textLayer.fill = [CPTFill fillWithImage:background];
textLayer.paddingLeft = 2.0;
textLayer.paddingTop = 2.0;
textLayer.paddingRight = 2.0;
textLayer.paddingBottom = 2.0;
symbolTextAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
symbolTextAnnotation.contentLayer = textLayer;
symbolTextAnnotation.contentAnchorPoint = CGPointMake(0.5, 0.0);
symbolTextAnnotation.displacement = CGPointMake(0.0, 10.0);
[graph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];
}发布于 2016-02-27 13:53:25
在绘图空间委托中,使用绘图上的-dataIndexFromInteractionPoint:方法查找与接触点最近的数据点的索引。一旦您有了数据索引,使用您已经创建和显示注释的代码。
https://stackoverflow.com/questions/35629209
复制相似问题