2013-12-09 36 views
0

我有一个金融时间系列的蜡烛棒图。假设图表上有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 :)但他们不是绘图空间的一部分(即他们没有缩放或平移图表,这是我的情况所需的行为)

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

回答

0

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

+0

工作就像一个魅力!万分感谢! – dhunds