2014-01-14 2 views
2

Мои высоты в барах, кажется, уменьшаются и растут по мере добавления большего количества данных на мой график. Можно ли исправить это так, чтобы он оставался неизменным (скажем, 10 пикселей высотой) каждый раз?Правильный способ установки ширины полосы в ячейке ядра?

Вот что я думаю, что соответствующий код:

#define kBarHeight 10 

-(void)configurePlots { 




    CPTBarPlot *countryPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:19/255.0 green:221/255.0 blue:187/255.0 alpha:1] horizontalBars:YES]; 

    countryPlot.identifier = @"CountryPlot"; 

    CPTBarPlot *timeZonePlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:30/255.0 green:33/255.0 blue:36/255.0 alpha:1] horizontalBars:YES]; 
    timeZonePlot.identifier = @"TimeZonePlot"; 


    CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init]; 
    barLineStyle.lineColor = [CPTColor lightGrayColor]; 
    barLineStyle.lineWidth = 0.5; 

    CPTGraph *countryGraph = self.countryGraph.hostedGraph; 
    CPTGraph *timeZoneGraph = self.timeZoneGraph.hostedGraph; 

    countryPlot.dataSource = self; 
    countryPlot.delegate = self; 
    countryPlot.barWidth = CPTDecimalFromDouble(kBarHeight); 
    countryPlot.baseValue = CPTDecimalFromString(@"0"); 
    countryPlot.lineStyle = barLineStyle; 
    countryPlot.barOffset = CPTDecimalFromFloat(0.25f); 
    countryPlot.labelOffset = -10.0; 
    [countryGraph addPlot:countryPlot toPlotSpace:countryGraph.defaultPlotSpace]; 


    timeZonePlot.dataSource = self; 
    timeZonePlot.delegate = self; 
    timeZonePlot.baseValue = CPTDecimalFromString(@"0"); 
    timeZonePlot.barWidth = CPTDecimalFromDouble(kBarHeight); 
    timeZonePlot.lineStyle = barLineStyle; 
    timeZonePlot.labelOffset = -10.0; 
    timeZonePlot.barOffset = CPTDecimalFromFloat(0.25f); 

    [timeZoneGraph addPlot:timeZonePlot toPlotSpace:timeZoneGraph.defaultPlotSpace]; 

} 

//Setting the ranges - possibly the incorrect part? 
CPTXYPlotSpace *countryPlotSpace = (CPTXYPlotSpace *) countryGraph.defaultPlotSpace; 
    CSGeoStat *stat = (CSGeoStat *) self.countryData[self.countryData.count-1]; 
    countryPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(stat.count * 1.1)]; 
    countryPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-20.0) length:CPTDecimalFromFloat([self.countryData count]*kBarHeight*1.5)]; 

    CPTXYPlotSpace *timeZonePlotSpace = (CPTXYPlotSpace *) timeZoneGraph.defaultPlotSpace; 
    stat = (CSGeoStat *) self.timeZoneData[self.timeZoneData.count-1]; 
    timeZonePlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(stat.count * 1.1)]; 
    timeZonePlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-20.0) length:CPTDecimalFromFloat([self.timeZoneData count]*kBarHeight*1.5)]; 

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index { 
    NSNumber *num = @0; 
    //Bars are horizontal, too! 
    switch (fieldEnum) { 
     case CPTBarPlotFieldBarTip: 
      if ([plot.identifier isEqual:@"CountryPlot"]) { 
       num = [NSNumber numberWithInteger:[self.countryData[index] count]]; 
      } else { 
       num = [NSNumber numberWithInteger:[self.timeZoneData[index] count]]; 

      } 
      break; 

     default: 
      num = [NSNumber numberWithInteger:(index*(kBarHeight+3)) + kBarHeight/2 ]; 

      break; 
    } 
    return num; 

} 

ответ

7

Попробуйте это:

countryPlot.barWidthsAreInViewCoordinates = YES; 
countryPlot.barWidths = 10.0; 

Первая строка сообщает Core, Plot использовать координаты просмотра, а не координаты участка.

Смежные вопросы