2015-02-02 1 views
0

점을 선택,하지만 난 선택하면 다른 지점에서 다른 설정 색상의 포인트는 어떻게 구현, 구별하는이 시점에서 희망핵심 플롯 덕분에 많이 나는 성공적으로 포인트를 선택한

방법 이 부분 만 빨간색으로 설정하십시오.

How to set up only this one in red

- (무효) 산점도 (CPTScatterPlot *) 플롯 plotSymbolWasSelectedAtRecordIndex (NSUInteger) 인덱스 { CPTXYGraph 그래프 = (CPTXYGraph) _graph;

if (_symbolTextAnnotation){ 
    [graph.plotAreaFrame.plotArea removeAnnotation:_symbolTextAnnotation]; 
    _symbolTextAnnotation = nil; 
} 

// Setup a style for the annotation 
CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle]; 
hitAnnotationTextStyle.color = [CPTColor whiteColor]; 
hitAnnotationTextStyle.fontSize = 16.0; 
hitAnnotationTextStyle.fontName = @"Helvetica-Bold"; 

// Determine point of symbol in plot coordinates 
NSDictionary *dataPoint = _plotData[index]; 

NSNumber *x = dataPoint[@"x"]; 
NSNumber *y = dataPoint[@"y"]; 

NSArray *anchorPoint = @[x, y]; 

float yValue = [y floatValue]; 

NSString *yString = [NSString stringWithFormat:@"%.1f",yValue]; 

CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle]; 
CPTImage *background = [CPTImage imageWithCGImage:[UIImage imageNamed:@"bg_red"].CGImage]; 
textLayer.fill   = [CPTFill fillWithImage:background]; 
textLayer.paddingLeft = 2.0; 
textLayer.paddingTop = 2.0; 
textLayer.paddingRight = 2.0; 
textLayer.paddingBottom = 2.0; 

self.symbolTextAnnotation     = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint]; 
_symbolTextAnnotation.contentLayer  = textLayer; 
_symbolTextAnnotation.contentAnchorPoint = CGPointMake(0.5, 0.0); 
_symbolTextAnnotation.displacement  = CGPointMake(0.0, 10.0); 
[graph.plotAreaFrame.plotArea addAnnotation:_symbolTextAnnotation]; 

}

+0

에릭, 고마워, 이미 팁에 따라 문제를 해결했습니다 – ilyon

답변

1

-symbolForScatterPlot:recordIndex: 소스 메소드를 구현. nil을 반환하면 기본값 인 plotSymbol, [NSNull null]을 사용하여 기호를 표시하지 않거나 CPTPlotSymbol을 사용하여 해당 데이터 색인에 해당 기호를 표시 할 수 있습니다.

+0

완벽하게 작동합니다. 고마워. – ilyon

관련 문제