2016-05-31 22 views
0

Ich habe ein Datum wie dieWie fügt man SetMajorIntervalLength im Core Plot hinzu?

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

Ich brauche diese Daten unten in x-Achse mit Intervall 2.

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

hinzufügen Wie kann ich diese in Kernstück Linie erreichen Diagramm.

Antwort

0

bekam ich die Lösung

`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; 
` 

i unten Code hinzugefügt

if(i%2 == 0) 
    { 
     [monthLabelset addObject:monthsLabel]; 
     [monthsDataset addObject:month]; 
    } 
Verwandte Themen