Ios 向烛台图表添加多个注释

Ios 向烛台图表添加多个注释,ios,objective-c,core-plot,Ios,Objective C,Core Plot,我有一个金融时间序列的蜡烛棒图。假设图表上有100支蜡烛,根据某些标准,我列出了20个要注释的点(即在相应蜡烛附近显示图像)。所有20个点应同时进行注释。可以添加单个注释,如下所示: //the image to display UIImage *flag = [UIImage imageNamed:@"flag.png"]; CPTImage *flagImage = [CPTImage imageWithCGImage:flag.CGImage

我有一个金融时间序列的蜡烛棒图。假设图表上有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(或子类)。即使经过多次尝试,我也无法在图表上正确添加图层和相应的图像注释。我添加了多个CPTLayer(使用addSublayer:)失败,但它们不是绘图空间的一部分(即,它们没有缩放或平移图表,这是我的情况下所需的行为)


有人能帮助实现这种行为吗?如果需要,我很乐意提供有关问题/代码的更多信息。

可以添加到图层的注释数量没有限制。设置注释内容层的大小以确保其可见。使用
-initWithFrame:
创建它,或稍后设置
边界