2011-08-09 2 views
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); 
} 

답변

0

이 기준점을 결정하는 코드는 다음과 같습니다

NSNumber *x = [[plotData objectAtIndex:index] valueForKey:@"x"]; 
NSNumber *y = [[plotData objectAtIndex:index] valueForKey:@"y"]; 
NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil]; 

그것은 당신의 플롯 데이터가 "X"와 "Y"키 사전의 배열의 NSNumber 개체로 저장됩니다 가정합니다. 데이터가 다른 방법으로 저장되면 값을 다르게 추출해야합니다. 중요한 것은 NSArray에있는 두 개의 숫자를 먼저 x 값과 y 값으로 패키징하는 것입니다.

+0

문제는 x 값과 y 값을 얻는 것이지만 올바른 방향으로 나를 인도했을 것입니다. 나는 키 이름이 다르다고 생각한다. 내 코드에서 로그 문을 사용하여 x 및 y를 로그에 기록하고 null을 반환합니다. 정보 주셔서 감사합니다 – zambono

관련 문제