2011-12-07 4 views
2

코코아의 코어 플롯에서 CPTBarPlot에 문제가 있습니다. 즉, 막대의 스텝 너비를 제어 할 수 없습니다. X 축 틱은 일반적으로 1에서 무한대까지의 정수로 설정되고 Scatter Plot을 그리면 작동합니다.코어 플롯의 CPTBarPlot에서 X 축 틱과 정렬되지 않은 막대

그러나 막대 작도가 그려지면 첫 번째 눈금에서 첫 번째 열만 시작됩니다 (물론 올바른 오프셋을 사용하여). 둘째 샷과 같이 매우 번째 및 모든 다른 약간 더 그 틱 형태 : I하지만,이를 제어하기위한 임의의 속성을 발견하지

enter image description here

, 그 데이터 소스에있어서 발견

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 

스 캐터 플롯을 그릴 때와 다른 방식으로 작동합니다. 즉, CPTBarPlotBindingBarTips 인 정수 3 만 열거하고 다른 상수는 열거하지 않습니다. 특히 CPTBarPlotBindingBarLocations 부재로 인해 괴롭습니다.

Plot Gallery mac 데모 프로젝트에서 VerticalBarChart를 시작한 경우 동일한 방법으로 동일한 순서로 3,4 및 2 개의 상수가 열거된다는 것을 확인했습니다.

코어 플롯 0.9를 사용하고 있습니다. 즉,이 데모와 동일하다고 생각합니다. 여전히 ...

어떻게 해결할 수 있습니까?

다음은 X 축의 레이블 및 틱에 대한 전체 코드입니다.

x.labelRotation = M_PI/4; 
    x.labelingPolicy = CPTAxisLabelingPolicyNone; 
    x.labelOffset = 0.0; 

    CPTMutableTextStyle *labelStyle = [CPTMutableTextStyle textStyle]; 
    labelStyle.fontSize = 9.0; 
    x.labelTextStyle = labelStyle; 

// NSMutableArray *dateArray = [dataSeries objectAtIndex:0]; 
    NSMutableArray *customTickLocations = [NSMutableArray array]; 
    NSMutableArray *xAxisLabels = [NSMutableArray array]; 

    for (int i=0;i<[dataSeries count];i++) { 

     [customTickLocations addObject:[NSDecimalNumber numberWithInt:i+1]]; 
     [xAxisLabels addObject:[dataSeries objectAtIndex:i]]; 

    } 

    // [customTickLocations addObject:[NSDecimalNumber numberWithInt:[dateArray count]]]; 

    NSUInteger labelLocation = 0; 
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 
    for (NSNumber *tickLocation in customTickLocations) { 
     CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle]; 
     newLabel.tickLocation = [tickLocation decimalValue]; 
     newLabel.offset = x.labelOffset + x.majorTickLength; 
     newLabel.rotation = M_PI/4; 
     [customLabels addObject:newLabel]; 
     [newLabel release]; 
    } 

    [x setMajorTickLocations:[NSSet setWithArray:customTickLocations]]; 

    x.axisLabels = [NSSet setWithArray:customLabels]; 

나는

답변

2

field 매개 변수는이 열거의 멤버 중 하나가 될 것입니다 .... 산포도가 동일한 플롯 공간에 그려진과 완벽하게 일치 할 때 같은 진드기가 사용되는 것을 추가해야 : 플롯의 plotRange 속성이 전무 (기본값)입니다

typedef enum _CPTBarPlotField { 
    CPTBarPlotFieldBarLocation = 2, ///< Bar location on independent coordinate axis. 
    CPTBarPlotFieldBarTip  = 3, ///< Bar tip value. 
    CPTBarPlotFieldBarBase  = 4 ///< Bar base (used only if barBasesVary is YES). 
} CPTBarPlotField; 

경우, 플롯 각 막대의 위치 및 팁에 대한 데이터 소스를 요청합니다. barBasesVary == YES 인 경우 각 막대의 기준 값도 묻습니다.

+0

늦게 답변드립니다. 여기서 쓴 것은 작동합니다. barBasesVary가 yes가 아니면 CPTBarPlotFieldBarTip 만 대리자에 의해 반복되고 다른 두 열거는 반복되지 않습니다. 그러나 이것을 구현해도 bar step offset의 문제는 해결되지 않습니다 ... 어쨌든 고마워요. – mbpro

+0

바 위치와 주요 틱 위치가 일치하지 않습니다. 솔루션은 사용중인 축 레이블 지정 정책과 데이터 소스가 막대 위치를 계산하는 방법에 따라 달라집니다. 플롯 설정 및 데이터 소스 코드를 게시하여 수정 방법에 대한보다 구체적인 제안을 제공 할 수 있습니다. –

+0

코드를 추가했습니다. 죄송합니다. sam 코드가 동일한 데이터를 가진 산점도와 완벽하게 일치한다는 사실을주의하십시오. – mbpro

관련 문제