2016-05-31 8 views
0

私が持っている私は、間隔をあけてx軸へのデータの下にこれらを追加する必要があることコアプロットでsetMajorIntervalLengthを追加するには?

(@"jan", @"feb", @"mar", @"apr", @"may", @"jun", @"jul", @"aug", @"sep", @"oct", @"nov", @"dec") 

などのデータを、私はコアプロットラインでこれを達成するにはどうすればよい2.

`(@"jan", @"mar", @"may", , @"jul", @"sep", @"nov")` 

チャート

答えて

0

私は私がコード

if(i%2 == 0) 
    { 
     [monthLabelset addObject:monthsLabel]; 
     [monthsDataset addObject:month]; 
    } 
の下に加えた溶液

`NSMutableArray *monthLabelset = [[NSMutableArray alloc]init]; 
    NSMutableArray *monthsDataset = [[NSMutableArray alloc]init]; 
    NSArray *months = [[NSArray alloc]initWithObjects:@"jan",@"feb",@"mar",@"apr",@"may",@"jun",@"jul",@"aug",@"sep",@"oct",@"nov",@"dec", nil]; 

    for (int i = 0; i<months.count; i++) 
    { 
     CPTAxisLabel *monthsLabel = [[CPTAxisLabel alloc]initWithText:[months objectAtIndex:i] textStyle:xAxis.labelTextStyle]; 
     monthsLabel.tickLocation = [NSNumber numberWithInt:i]; 
     monthsLabel.offset  = 3.0; 
     NSString *month = [months objectAtIndex:i]; 
     if (monthsLabel) 
     { 
      if(i%2 == 0) 
      { 
       [monthLabelset addObject:monthsLabel]; 
       [monthsDataset addObject:month]; 
      } 

     } 


    } 

    NSMutableSet *monthLabels = [[NSMutableSet alloc]initWithArray:monthLabelset]; 
    NSMutableSet *monthsData = [[NSMutableSet alloc]initWithArray:monthsDataset]; 
    xAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    xAxis.axisLabels = monthLabels; 
    xAxis.majorTickLocations = monthsData; 

     plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:11]]; 
     plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:(yAxisMin)] length:[NSNumber numberWithInt:(yAxisMax - yAxisMin)]]; 
     [xAxis setMajorIntervalLength:[NSNumber numberWithInt:2]]; 
     [yAxis setMajorIntervalLength:[NSNumber numberWithInt:1]]; 
     [yAxis setLabelFormatter:axisFormatter]; 

     CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy]; 
     CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy]; 
     [xRange expandRangeByFactor:[NSNumber numberWithDouble:1.06]]; 
     [yRange expandRangeByFactor:[NSNumber numberWithDouble:1.06]]; 
     plotSpace.xRange = xRange; 
     plotSpace.yRange = yRange; 
` 

を得ました

関連する問題