ios - Core Plot 1.0 我的触摸注释不起作用

标签 ios annotations core-plot

我已经为此工作了几天,但感到非常难过。我正在尝试在核心图中制作一个图表,允许用户插入数据点并获取坐标。我制作了一个仅制作线性图的示例应用程序。我的问题是我无法使用触摸功能。我在核心情节网站上引用了许多情节,但我就是无法在我的应用程序中使用它。这是我所做的;

在我的标题中,我创建了一个属性 CPTPlotSpaceAnnotation *annotation。我还使用了接口(interface) ViewController : UIViewController 。

在我的实现中,我合成了注释。在我的 ViewDidAppear 方法中,我使用 CGPointMake 创建了一个数据数组。

NSMutableArray *linearstuff = [NSMutableArray array];

for (int i = 0; i < 100; i ++)
{
    float y = (b * (l)) + c;
    [linearstuff addObject:[NSValue valueWithCGPoint:CGPointMake(l, y)]];
    l = l + inc;
}

self.data = linearstuff;
[self initPlot];

我的方法 initPlot 配置图形并有几个配置方法。因此,在一个名为 configurePlots 的方法中,我分配并初始化了一个名为 linearGraph 的 CPTScatterPlot。我也在该方法中使用了 linearGraph.plotSymbolMarginForHitDetection。然后对于 plotSymbolWasSelectedAtRecordIndex,我执行了以下操作。

- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
NSLog(@"touch");
CPTGraph *graph = self.hostView.hostedGraph;

if (_annotation)
{
    [graph.plotAreaFrame.plotArea removeAnnotation:_annotation];
    _annotation = nil;
}

CPTMutableTextStyle *annotationTextStyle = [CPTMutableTextStyle textStyle];
annotationTextStyle.color = [CPTColor whiteColor];
annotationTextStyle.fontSize = 16.0f;
annotationTextStyle.fontName = @"Helvetica-Bold";

NSValue *value = [self.data objectAtIndex:index];
CGPoint point = [value CGPointValue];
NSString *number1 = [NSString stringWithFormat:@"%.2f", point.x];
NSString *number2 = [NSString stringWithFormat:@"%.2f", point.y];

NSLog(@"x and y are, %.2f, %.2f", point.x, point.y);
NSLog(@"number1 and number2 are, %.2f, %.2f", point.x, point.y);

NSNumber *x = [NSNumber numberWithFloat:point.x];
NSNumber *y = [NSNumber numberWithFloat:point.y];

NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];

NSString *final = [number1 stringByAppendingString:number2];
NSLog(@"final is %@",final);


CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:final style:annotationTextStyle];
_annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
_annotation.contentLayer = textLayer;
_annotation.displacement = CGPointMake(0.0f, 0.0f);
[graph.plotAreaFrame.plotArea addAnnotation:_annotation];
}

我试图按照我在核心情节网站上看到的内容进行操作。我拿了我的数组并得到了索引。我将这些值放在一个 NSNumber 中,为注释创建一个字符串。但是,它没有出现在图表上。有谁知道我做错了什么?任何见解将不胜感激。我已经阅读了许多关于 SO 的核心情节问题,但找不到对我的情况有帮助的东西。提前谢谢你。

最佳答案

对于任何关注此内容的人。我首先要再次感谢 Eric Skroch 的所有帮助!!!!但我终于发现我做错了什么。我已经将 viewController 设为绘图委托(delegate),但是,我在制作绘图时并没有这么说。我添加了 linearGraph.delegate = self;现在 plotSymbol... 方法被调用了!谢谢@Eric Skroch。

关于ios - Core Plot 1.0 我的触摸注释不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12394050/

相关文章:

Java使用Annotation创建类的实例

ios - Core Plot numberForPlot 的值不会大于 1

objective-c - EXC_BAD_ACESS 错误

iPhone (iOS) 应用程序使用本地 sqlite 并希望在多个设备之间同步

ios - 声明的方法必须返回 void(不是 float)

iOS Core-Plot 滚动效果不佳

objective-c - 如何将图例添加到核心图的散点图

ios - 单击搜索栏不会打开键盘(iOS Swift)

java - 如何为 JUnit 测试声明 "mixins"?

java - 为什么 @Deprecated 注释不触发有关方法的编译器警告?