首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向烛台图表添加多个注释

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

Stack Overflow用户
提问于 2013-12-09 16:22:33
回答 1查看 162关注 0票数 0

我有一个财政时间序列的烛光图。假设图表上有100支蜡烛,基于特定的标准,我列出了20点注释(即显示对应蜡烛附近的图像)。所有20点都应同时进行注释。可以添加一个注释,如下所示:

代码语言:javascript
复制
//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:的调用),但它们不是绘图空间的一部分(也就是说,它们没有缩放或平移图表,这在我的例子中是需要的行为)。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-10 00:38:25

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20475454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档