2012-11-29 3 views
0

코어 플롯 프레임 워크를 사용하여 그래프를 그리는 중입니다. 사용자가 폴트 기호를 탭하면 텍스트가 표시됩니다. 하지만 제 문제는 텍스트가 플롯 기호에 겹쳐져 있다는 것입니다. 이 문제를 극복하는 방법. 제발 도와주세요. 선형 차트에서 plotsymbol과 plotsymboltext 사이의 간격을 늘리는 방법은 무엇입니까?

enter image description here

내 코드가 어떤 실수 나에게이 이야기되고이

- (void) scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index{ 
if ([plot.identifier isEqual:@"Green Plot"]) { 
    selectedLineIndex1 = index; 
    selectedLineIndex2 = -1; 
    [graph reloadData]; 
} 
else if ([plot.identifier isEqual:@"Blue Plot"]) { 
    selectedLineIndex1 = -1; 
    selectedLineIndex2 = index; 
    [graph reloadData]; 

} }

- (CPTLayer *) dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index { 
// Setup a style for the annotation text 
CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle]; 
hitAnnotationTextStyle.color = [CPTColor blackColor]; 
hitAnnotationTextStyle.fontSize = 18.0f; 
hitAnnotationTextStyle.fontName = @"Verdana-Bold"; 

// Now add the annotation text to the plot 
CPTTextLayer *selectedText = [CPTTextLayer layer]; 
selectedText.textStyle = hitAnnotationTextStyle; 
selectedText.position = CGPointMake(0.0,40.0f); 

if (index == selectedLineIndex1 && [plot.identifier isEqual:@"Green Plot"]) { 
    selectedText.text = [NSString stringWithFormat:@"%.1f",[[dataForPlot objectAtIndex:index] floatValue]]; 
} 
else if (index == selectedLineIndex2 && [plot.identifier isEqual:@"Blue Plot"]) { 
    selectedText.text = [NSString stringWithFormat:@"%.1f",[[yPoints objectAtIndex:index] floatValue]]; 
} 
return selectedText;} 

같은 또는 다른 방법이 그냥 날 몇 가지를 제공하시기 바랍니다 제안 견본.

미리 감사드립니다.

+1

어떻게 그려야합니까? 주석? 데이터 레이블? 다른 방법이 있니? –

+0

Datalables를 사용하고 있습니다. – Thukaram

답변

1

선형 차트를 만들 때 솔루션을 찾았습니다. labelOffSet을 선형 차트에 추가하십시오.

예제 코드.

CPTScatterPlot *boundLinePlot2 = [[[CPTScatterPlot alloc] init] autorelease]; 
CPTMutableLineStyle *lineStyle2 = [CPTMutableLineStyle lineStyle]; 
lineStyle2.miterLimit = 1.0f; 
lineStyle2.lineWidth = 3.0f; 
lineStyle2.lineColor = [CPTColor redColor]; 
boundLinePlot2.dataLineStyle = lineStyle2; 
boundLinePlot2.identifier = @"Green Plot"; 
boundLinePlot2.dataSource = self; 
boundLinePlot2.delegate = self; 

이 줄을 챠트에 추가하면 문제가 해결됩니다.

boundLinePlot2.labelOffset = 10.0f; 
boundLinePlot2.labelRotation = M_PI_4;