2012-02-07 97 views
0

我在iOS應用程序中使用核心繪圖,並且想要格式化軸的步驟。我所得到的是0.5的步驟,我不知道還有什麼可以改變的。我剔地點應由5,10,15和20核心繪圖:刻度間隔

這裏是吸引我的軸代碼:

-(void) addAxis{ 

    // Create grid line styles 
    CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle]; 
    majorGridLineStyle.lineWidth = 1.0f; 
    majorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.75]; 

    NSSet *majorTickLocations = [NSSet setWithObjects:[NSDecimalNumber zero], 
           [NSDecimalNumber numberWithUnsignedInteger:5], 
           [NSDecimalNumber numberWithUnsignedInteger:10], 
           [NSDecimalNumber numberWithUnsignedInteger:15], 
           [NSDecimalNumber numberWithUnsignedInteger:20], 
           nil]; 

    // Create axes 
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet; 
    CPTXYAxis *x = axisSet.xAxis; 
    { 
     x.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided; 
     x.tickDirection = CPTSignNone; 
     x.majorTickLocations = majorTickLocations; 
     x.labelOffset = 6.0; 
     x.labelRotation = M_PI/2; 
     x.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(19.0f)]; 
     x.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(30.0f)]; 
     x.title = @"Jahre"; 
     x.titleOffset = 35.0f; 
     x.titleLocation = CPTDecimalFromFloat(x.visibleRange.lengthDouble/2.0); 
     x.plotSpace = self.barPlotSpace; 
    } 

    CPTXYAxis *y = axisSet.yAxis; 
    { 
     y.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided; 
     y.majorTickLocations = majorTickLocations; 
     y.minorTicksPerInterval = 0; 
     y.preferredNumberOfMajorTicks = 8; 
     y.majorGridLineStyle = majorGridLineStyle; 
     y.axisLineStyle = nil; 
     y.majorTickLineStyle = nil; 
     y.minorTickLineStyle = nil; 
     y.labelOffset = 10.0; 
     y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(30.0f)]; 
     y.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(18.5f)]; 
     y.title = @"Sparbetrag"; 
     y.titleOffset = 40.0f; 
     y.titleLocation = CPTDecimalFromFloat(y.visibleRange.lengthDouble/2.0); 
     y.plotSpace = barPlotSpace; 
    } 

    // Set axes 
    self.graph.axisSet.axes = [NSArray arrayWithObjects:x, y, nil]; 
} 

回答

3

找到解決方案:應用主題會更改繪圖的繪畫行爲。如果我不應用主題 - 一切都很好。

因爲這不是很直觀。我期望一個主題只會改變顏色或者某些方面可以被覆蓋。

0

該代碼應該很好地工作 - you'll結束了刻度線和標籤在0,5,10,15和20處。visibleRangegridLinesRange的設置可能不正確 - 將它們保留爲默認值nil,以使軸和網格線延伸繪圖區域的整個寬度和高度。

如果要更改標籤的數字格式,請將labelFormatter設置爲新的NSNumberFormatter對象,該對象配置爲提供所需的數字格式。