我有一个财政时间序列的烛光图。假设图表上有100支蜡烛,基于特定的标准,我列出了20点注释(即显示对应蜡烛附近的图像)。所有20点都应同时进行注释。可以添加一个注释,如下所示:
//the image to display
UIImage *flag = [UIImage imageNamed:@"flag.png"];
CPTImage *flagImage = [CPTImage imageWithCGImage:flag.CGImage
scale:flag.scale];
CPTBorderedLayer *borderedLayer = [[CPTBorderedLayer alloc] init];
CPTMutableLineStyle *blackLineStyle = [CPTMutableLineStyle lineStyle];
[blackLineStyle setLineColor:[CPTColor blackColor]];
[blackLineStyle setLineWidth:1.0f];
[borderedLayer setBorderLineStyle:blackLineStyle];
[borderedLayer setFill:[CPTFill fillWithImage:flagImage]];
//the 'i' in the next statement is from a 'for' loop iterating over NSArrays: xCoordinates & yCoordinates, containing the corresponding coordinates for short-listed data points
NSArray *anchorPoint = [NSArray arrayWithObjects:[xCoordinates objectAtIndex:i], [yCoordinates objectAtIndex:i], nil];
CPTPlotSpaceAnnotation *alertAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:[[[self hostView] hostedGraph] defaultPlotSpace]
anchorPlotPoint:anchorPoint];
[alertAnnotation setContentLayer:borderedLayer];
[alertAnnotation setDisplacement:CGPointMake(0.0f, 10.0f)];
[[[[self hostView] hostedGraph] plotAreaFrame] addAnnotation:alertAnnotation];问题是一次只能托管一个CPTPlotSpaceAnnotation,所以每次我循环并执行addAnnotation时,都会丢失以前的注释。根据我的研究,它认为必须为每个注释分别添加一个CPTLayer (或子类)。即使经过多次尝试,我也无法在图表上正确地添加一个图层和相应的图像注释。我成功地添加了多个CPTLayers (使用对addSublayer:的调用),但它们不是绘图空间的一部分(也就是说,它们没有缩放或平移图表,这在我的例子中是需要的行为)。
有人能帮助如何实现这种行为吗?如果需要的话,我很乐意提供更多关于问题/代码的信息。
发布于 2013-12-10 00:38:25
您可以添加到一个层的注释的数量没有限制。设置注释内容层的大小以确保它是可见的。用-initWithFrame:创建它,或者稍后设置bounds。
https://stackoverflow.com/questions/20475454
复制相似问题