목표 : 데이터 당 개월의 고정 너비 열을 생성합니다.
문제점 : 열 너비는 # 데이터 포인트에 따라 다릅니다. 따라서 일부 라벨은 특정 월의 데이터 부족으로 인해
(예 : 'JanFeb'vs 'Jan ... Feb') 클러스터됩니다.사용자 정의 고정 너비 열/x- 레이블은 어떻게 만듭니 까?
다음 코드 스 니펫은/month라는 새 레이블을 만들지 만 x 축에 레이블을 정적으로 배치 할 수는 없습니다. 몇 가지 데이터 항목 (이하 점) 특정 달에 해당하는 경우 그래서 일부 레이블을 병합 할 수 있습니다
for (PerformanceDataItem *item in perfDataArray) {
if (![item.month isEqualToString:currentMonth]) {
currentMonth = item.month;
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:item.month textStyle:x.labelTextStyle];
newLabel.tickLocation = [[NSDecimalNumber numberWithInt:index] decimalValue];
newLabel.offset = 2;
[customLabels addObject:newLabel];
[newLabel release];
}
++index;
} // end for().
x.axisLineStyle = nil;
x.majorTickLineStyle = nil;
x.minorTickLineStyle = nil;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
NSSet* customlabelSet = [NSSet setWithArray:customLabels];
x.axisLabels = customlabelSet;
질문 :가 어떻게 데이터를 플롯 할 열 사용자 정의 된 고정 폭 세트를 만들 수 있습니까?
... 단지 x.labelingPolicy를
CPTAxisLabelingPolicyFixedInterval으로 설정하면 내 자신의 NSString 레이블을 사용하여 많은 숫자 (1.0 - x.0)로 x 축을 어지럽게 만든다.
또한 시도 : a) plotSpace.xRange; 및 b) x.majorIntervalLength를 변경하는 것.
기본 설정 : 맞춤 라벨 : CPTAxisLabelingPolicyFixedInterval
P.S. 얇은 컬럼을 넓히면 (데이터가 적을 때) 다음 달의 다음 데이터 포인트에 대한 외삽을 그릴 것이라고 가정합니다. 이웃 달의 점 집합과 같은 누락 데이터 점을 채울 필요가 없습니다.
plotSpace.xRange :
============================
솔루션 의견에 따라 = [CPTPlotRange plotRangeWithLocation : CPTDecimalFromUnsignedInteger (0) 길이 : CPTDecimalFromUnsignedInteger (100)];
axisFixedInterval.majorIntervalLength = CPTDecimalFromDouble (25.0); NSDateComponents * dateComponents = [[NSDateComponents alloc] init];
// Set begining date to April 1, 2012: [dateComponents setMonth:4]; [dateComponents setDay:1]; [dateComponents setYear:2012]; [dateComponents setHour:0]; [dateComponents setMinute:0]; [dateComponents setSecond:0]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *refDate = [gregorian dateFromComponents:dateComponents]; [dateComponents release]; [gregorian release]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateStyle = kCFDateFormatterMediumStyle; [dateFormatter setDateFormat:@"MMM"]; CPTCalendarFormatter *calFormatter = [[[CPTCalendarFormatter alloc] initWithDateFormatter:dateFormatter] autorelease]; calFormatter.referenceDate = refDate; calFormatter.referenceCalendarUnit = kCFCalendarUnitMonth; axisFixedInterval.labelFormatter = calFormatter; [dateFormatter release];
...이 나에게 3 문자 개월의 고정 분포를 줄 것이다 : [4월 월 이세 7 월 8 월을] 5 틱 위치.
... plot_gallery_ios 예제에서.
이것은 내가 한 것입니다. –