2012-03-03 13 views
0

"Core-Plot"を使ってグラフをプロットしています。私は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 !!それは本当に良いと便利です! –

関連する問題