2013-02-25 41 views
0

在我的圖表中,majorGridLines對整個數字都能正常工作,但是當範圍介於3.0和0.0之間時,10個或更多的majorTickLocations。 tick位置在正確的位置,IE大約每0.3,但主要的GridLines與Tick不在同一位置,它們只落在整個數字1.0,2.0,3.0等。我怎樣才能讓majorGridLines工作與不完整的數字,並與tickLocations水平?核心圖Y軸majorgridline只能落在整數上?

代碼如下:

NSMutableSet *yLabels = [NSMutableSet set]; 
NSMutableSet *yMajorLocations = [NSMutableSet set]; 

for (int i=-1; i<numYAxisLabels; i++) { 

     id jAsID = [NSNumber numberWithInt:(int)j]; 
     int jAsInt = [jAsID integerValue]; 

     CPTAxisLabel *label; 
     if(majorIncrement < 1) 
      label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%.1f", j] textStyle:y.labelTextStyle]; 
     else 
      label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%d", jAsInt] textStyle:y.labelTextStyle]; 

     NSDecimal location = CPTDecimalFromFloat(j); 
     label.tickLocation = location; 
     label.offset = -y.majorTickLength - y.labelOffset; 

     [yLabels addObject:label]; 
     [yMajorLocations addObject:jAsID]; 

     currTopYLabelLocation = j; 
     j += majorIncrement; 
    } 
    y.axisLabels = yLabels; 
    y.majorTickLocations = yMajorLocations; 

回答

1

蜱位置從一系列jAsID值的建造。在問題中給出的代碼中,j在創建NSNumber對象之前被轉換爲整數值。

+0

謝謝Eric,就是這樣!我的道歉,我認爲情況並非如此,因爲tickLocations出現的很好。 – Baconbeastnz 2013-02-25 01:48:49