2010-06-17 15 views
0

J'ai presque terminé avec un graphique de noyau-intrigue que j'ai travaillé pendant quelques jours maintenant. Il y a quelque chose que je ne suis toujours pas capable de faire (et je ne trouve pas de documentation à ce sujet), c'est de changer les étiquettes de l'axe des x pour ce dont j'ai besoin. Aujourd'hui, j'ai un axe x avec une étiquette entière affichée toutes les 5 valeurs: "5 10 15 ...", j'ai besoin d'avoir des étiquettes correspondant aux dernières 24 heures. Par exemple, s'il est 15h00, j'aurais besoin de labels comme: "15 16 17 ... 23 0 1 2 .. 15" Je pensais utiliser un NSArray pour cela et le passer à l'espace plot.xRange mais je ne sais pas savoir si c'est la bonne façon de le faire. Voici mon code:iphone, en utilisant un tableau pour définir dans la plage de traceur de base

  CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
      plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15) 
                  length:CPDecimalFromFloat(xmax + 15)]; 
      plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-1000) 
                  length:CPDecimalFromFloat(4300)]; 


      // Setup axis 
      CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 
      CPLineStyle *lineStyle = [CPLineStyle lineStyle]; 
      lineStyle.lineColor = [CPColor whiteColor]; 
      lineStyle.lineWidth = 1.0f; 
      CPTextStyle *cyanStyle = [CPTextStyle textStyle]; 
      cyanStyle.color = [CPColor cyanColor]; 
      NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
      [formatter setMaximumFractionDigits:0]; 

      axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
      axisSet.xAxis.minorTicksPerInterval = 0; 
      axisSet.xAxis.majorTickLineStyle = lineStyle; 
      axisSet.xAxis.minorTickLineStyle = lineStyle; 
      axisSet.xAxis.axisLineStyle = lineStyle; 
      axisSet.xAxis.majorTickLength = 5.0f; 
      axisSet.xAxis.labelOffset = 3.0f; 
      axisSet.xAxis.labelExclusionRanges = [NSArray arrayWithObjects: 
             [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15) 
                    length:CPDecimalFromFloat(15)], 
             nil]; 
      axisSet.xAxis.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromInteger(0) length:CPDecimalFromInteger(xmax)]; 
      axisSet.xAxis.labelFormatter = formatter; 
      axisSet.xAxis.title = @"Hour"; 
      axisSet.xAxis.titleOffset = 25.0f; 
      axisSet.xAxis.titleLocation = CPDecimalFromFloat(25.0f); 
      axisSet.xAxis.titleTextStyle = cyanStyle; 

Toute aide serait la bienvenue vraiment :) Merci beaucoup, Luc

Répondre

0

j'ai finalement trouvé la solution en utilisant une étiquette personnalisée:

  NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0], 
                    [NSDecimalNumber numberWithInt:5], 
                    [NSDecimalNumber numberWithInt:10], 
                    [NSDecimalNumber numberWithInt:15], 
                    [NSDecimalNumber numberWithInt:20], 
                    [NSDecimalNumber numberWithInt:25], 
                    [NSDecimalNumber numberWithInt:30], 
                    [NSDecimalNumber numberWithInt:35],             
                    [NSDecimalNumber numberWithInt:40],             
                    nil]; 
      NSArray *xAxisLabels = [NSArray arrayWithObjects:@"15",@"18",@"21",@"0",@"3",@"6",@"9",@"12",@"15",nil]; 

      NSUInteger labelLocation = 0; 
      NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 
      for (NSNumber *tickLocation in customTickLocations) { 
       CPAxisLabel *newLabel = [[CPAxisLabel 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]; 

Vous avez encore des quelque chose à clarifier mais c'est sûrement le chemin à parcourir :) Luc