2012-03-03 15 views
0

"코어 플롯"을 사용하여 그래프를 플로팅합니다. x 축에 다음 코드를 사용하면 올바르게 작동합니다.눈금 표시 X 축 레이블 표시 중에 사라집니다.

  axisSet.xAxis.titleTextStyle = textStyle; 
      axisSet.xAxis.titleOffset = 2.0f; 
      axisSet.xAxis.axisLineStyle = axisLineStyle; 
      axisSet.xAxis.majorTickLineStyle = axisLineStyle; 
      axisSet.xAxis.minorTickLineStyle = axisLineStyle; 
      axisSet.xAxis.labelTextStyle = textStyle; 
      axisSet.xAxis.labelOffset = 0.0f; 
      axisSet.xAxis.minorTicksPerInterval = 1; 
      axisSet.xAxis.minorTickLength = 0.0f; 
      axisSet.xAxis.majorTickLength = 5.0f; 

      plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(7.0f)]; 
      axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(1.0f); 

하지만이 같은 코드를 사용

// ----------------------------- ---------------------------------------------

NSArray *arr; 
    NSString *month; 
    NSString *days; 

    NSDateFormatter *format=[[NSDateFormatter alloc]init]; 
    [format setDateFormat:@"yyyy/MM/dd"]; 

    NSDate *day=[NSDate date]; 
    NSDate *week = [day dateByAddingTimeInterval: -604800.0]; 
    NSDate *day1 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:week]; 
    NSDate *day2 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day1]; 
    NSDate *day3 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day2]; 
    NSDate *day4 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day3]; 
    NSDate *day5 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day4]; 
    NSDate *day6 = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day5]; 
    NSDate *today = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:day6]; 

    NSString *str1 =[format stringFromDate:day1]; 
    arr=[str1 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str1=[days stringByAppendingFormat:@":%@",month]; 

    NSString *str2 =[format stringFromDate:day2]; 
    arr=[str2 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str2=[days stringByAppendingFormat:@":%@",month]; 


    NSString *str3 =[format stringFromDate:day3]; 
    arr=[str3 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str3=[days stringByAppendingFormat:@":%@",month]; 

    NSString *str4 =[format stringFromDate:day4]; 
    arr=[str4 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str4=[days stringByAppendingFormat:@":%@",month]; 

    NSString *str5 =[format stringFromDate:day5]; 
    arr=[str5 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str5=[days stringByAppendingFormat:@":%@",month]; 


    NSString *str6 =[format stringFromDate:day6]; 
    arr=[str6 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str6=[days stringByAppendingFormat:@":%@",month]; 


    NSString *str7 =[format stringFromDate:today]; 
    arr=[str7 componentsSeparatedByString:@"/"]; 
    month=[arr objectAtIndex:1]; 
    days=[arr objectAtIndex:2]; 
    str7=[days stringByAppendingFormat:@":%@",month]; 
    //-------------------------------------------------------------------------------- 

    [email protected]"-----One Week----->"; 
    axisSet.xAxis.titleTextStyle =textStyle; 
    axisSet.xAxis.titleOffset = 10.0f; 
    axisSet.xAxis.axisLineStyle = axisLineStyle; 
    axisSet.xAxis.labelTextStyle = mtextStyle; 
    axisSet.xAxis.labelOffset = 0.0f; 
    axisSet.xAxis.majorTickLength = 1.0f; 

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(7)]; 
    axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(1.0f); 

    //--------------labeling X-axis------------------------------------------ 

    axisSet.xAxis.labelRotation = M_PI/4; 
    axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    NSArray *customTickLocations = [NSArray arrayWithObjects: 
            [NSDecimalNumber numberWithInt:1], 
            [NSDecimalNumber numberWithInt:2], 
            [NSDecimalNumber numberWithInt:3], 
            [NSDecimalNumber numberWithInt:4], 
            [NSDecimalNumber numberWithInt:5], 
            [NSDecimalNumber numberWithInt:6], 
            [NSDecimalNumber numberWithInt:7],nil]; 
    NSArray *xAxisLabels = [NSArray arrayWithObjects:str1,str2,str3,str4,str5,str6,str7,nil]; 
    NSUInteger labelLocation = 0; 
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 

    for (NSNumber *tickLocation in customTickLocations) 
    { 
     CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:axisSet.xAxis.labelTextStyle]; 
     newLabel.tickLocation = [tickLocation decimalValue]; 
     newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength; 
     [customLabels addObject:newLabel]; 
     [newLabel release]; 
    } 
    axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels]; 
    //--------------------------------------------------------------------------- 

그러면 x 축에 눈금이 사라집니다. 나는 사방을 수색했지만 관련 답변을 찾을 수 없습니다. 그러니 누구나 할 수 있으면 제발 말해줘. 미리 감사드립니다 !!

답변

0

CPTAxisLabelingPolicyNone 레이블 지정 정책에 따라 틱 위치를 별도로 제공해야합니다. 라벨에 유연성을 최대화 할 수 있으므로 모든 눈금에 레이블을 지정할 필요가 없으며 눈금이없는 위치에 레이블을 배치 할 수 있습니다.

axisSet.xAxis.majorTickLocations = [NSSet setWithArray:customTickLocations]; 

작은 눈금을 원할 경우 minorTickLocations도 설정해야합니다.

+0

내 질문에 동의하지 않았다고 생각합니다. 내 사용자 정의 레이블을 설정하는 동일한 위치에 눈금 표시를 원합니다. 나는 맞춤 라벨과 눈금 표시를 필요로한다는 의미입니다. –

+0

CPTAxisLabelingPolicyNone 라벨링 정책은 어떤 라벨링 작업도 수행하지 않습니다. 여기에는 눈금 표시 위치 결정이 포함됩니다. 게시 한 코드는 맞춤 라벨을 잘 만들 것입니다. 또한 축에 눈금을 원하는 위치를 알려줘야합니다. 눈금 위치 속성 (메이저 및/또는 마이너)을 설정하지 않으면 눈금 표시를 원하지 않는다고 가정합니다. –

+0

@thanks !! 그것은 정말로 좋고 도움이된다! –