Add multiple annotations to a Candlestick chart

I have a candle stick plot for a financial time series. Lets say there are 100 candles on the chart, based on certain criteria I short-list 20 points to annotate (i.e. show an image near the corresponding candle). All 20 points should carry the annotation simultaneously. A single annotation can be added, like so :

//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];

The problem is that only one CPTPlotSpaceAnnotation can be hosted at a time, so each time I loop through and perform addAnnotation: again the previous annotation is lost. Based on my research it figures that a CPTLayer (or subclass) has to be added for each annotation separately. Even after multiple attempts, I am unable to correctly add a layer and a corresponding image annotation to it on the chart. I unsuccessfully added multiple CPTLayers (using calls to addSublayer:) but they were not part of the Plot-space (i.e. they did not zoom or pan with the chart, which is the desired behaviour in my case)

Can someone help with how to achieve this behaviour? If needed, I will be happy to furnish more information about the problem/code.

Answers


There is no limit to the number of annotations you can add to a layer. Set the size of the annotation content layer to make sure it is visible. Create it with -initWithFrame: or set the bounds later.


Need Your Help

Is there an easy way to reorder items in a ListView

xaml windows-runtime winrt-xaml

I have a ListView data bound to an ObservableCollection. I set the CanReorderItems property to true.

How to fake DbContext.Entry method in Entity Framework with repository pattern

c# entity-framework unit-testing asp.net-mvc-4 repository-pattern

Because I want to unit test my code I have implemented the repository pattern in my MVC4 application. I managed to make a Context Interface, a fake Context and use a fake implementation of a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.