1
첫 번째 코어 플롯이 있는데 현재 주석을 구현하려고합니다. 나는 주석을 기록했고 x와 y 좌표는 null이다. 감사core-plot 주석 좌표가 null을 반환합니다.
-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
//CPTGraph* graph = [graphs objectAtIndex:0];
NSLog(@"add annotation called");
if (symbolTextAnnotation) {
[graph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
//[graph removeAnnotation:symbolTextAnnotation];
symbolTextAnnotation = nil;
}
// Setup a style for the annotation
CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
hitAnnotationTextStyle.color = [CPTColor whiteColor];
hitAnnotationTextStyle.fontSize = 16.0f;
hitAnnotationTextStyle.fontName = @"Helvetica-Bold";
// Determine point of symbol in plot coordinates
NSNumber *x = [[plotData objectAtIndex:index] valueForKey:@"x"];
NSNumber *y = [[plotData objectAtIndex:index] valueForKey:@"y"];
NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil];
NSLog(@"x %@, y %@",[[plotData objectAtIndex:index] valueForKey:@"x"],y);
// Add annotation
// First make a string for the y value
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
[formatter setMaximumFractionDigits:2];
NSString *yString = [formatter stringFromNumber:y];
// Now add the annotation to the plot area
CPTTextLayer *textLayer = [[[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle] autorelease];
symbolTextAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
symbolTextAnnotation.contentLayer = textLayer;
symbolTextAnnotation.displacement = CGPointMake(0.0f, 20.0f);
[graph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];
//[graph addAnnotation:symbolTextAnnotation];
CPTAnnotation *annot = [graph.plotAreaFrame.plotArea.annotations objectAtIndex:0];
NSLog(@"annot: %@", annot);
}
문제는 x 값과 y 값을 얻는 것이지만 올바른 방향으로 나를 인도했을 것입니다. 나는 키 이름이 다르다고 생각한다. 내 코드에서 로그 문을 사용하여 x 및 y를 로그에 기록하고 null을 반환합니다. 정보 주셔서 감사합니다 – zambono