2014-01-14 66 views
2

隨着更多數據添加到我的圖形中,我的酒吧高度似乎縮小和增長。是否有可能修復它,使它保持不變(每次10px)?在coreplot中設置條寬度的正確方法?

這就是我認爲是相關代碼:

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

第一行告訴核心地塊使用視圖座標,而不是情節座標。