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 :)但他們不是繪圖空間的一部分(即他們沒有縮放或平移圖表,這是我的情況所需的行爲)
有人可以幫助如何實現這種行爲?如果需要,我會很樂意提供有關問題/代碼的更多信息。
工作就像一個魅力!萬分感謝! – dhunds