2010-07-08 29 views
6

Tôi có vấn đề này kể từ một thời gian dài và tôi không thể tìm thấy bất cứ điều gì để giải quyết này. Tôi đọc một số diễn đàn nhưng không thể tìm được giải pháp làm việc. Tôi có mã sau:cốt lõi cốt lõi: vẫn không hiểu làm thế nào để có nhãn tùy chỉnh VÀ ve

// Adjust graph using above data     
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-10) length:CPDecimalFromFloat(xmax + 17)]; 
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-450) length:CPDecimalFromFloat(3750)]; 

// 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]; 

// x axis with custom labels 
axisSet.xAxis.labelingPolicy = CPAxisLabelingPolicyNone; 
axisSet.xAxis.majorTickLineStyle = lineStyle; 
axisSet.xAxis.axisLineStyle = lineStyle; 
axisSet.xAxis.majorTickLength = 3.0f; 
axisSet.xAxis.labelOffset = 3.0f; 

axisSet.xAxis.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromInteger(0) length:CPDecimalFromInteger(xmax)]; 
axisSet.xAxis.labelExclusionRanges = [NSArray arrayWithObjects: 
             [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-10) 
                    length:CPDecimalFromFloat(10)], 
             nil]; 

NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0], 
           [NSDecimalNumber numberWithInt:6], 
           [NSDecimalNumber numberWithInt:12], 
           [NSDecimalNumber numberWithInt:18], 
           [NSDecimalNumber numberWithInt:24], 
           [NSDecimalNumber numberWithInt:30], 
           [NSDecimalNumber numberWithInt:36], 
           [NSDecimalNumber numberWithInt:41],            
           [NSDecimalNumber numberWithInt:47],            
           nil]; 

    // This return the labels (11h, 14h, ..., 22h, ..) 
NSArray *xAxisLabels = [GPHelpers getHoursList:fromStr to:toStr]; 

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.majorTickLocations = [tickLocation decimalValue]; 
    newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength;     
    [customLabels addObject:newLabel]; 
    [newLabel release]; 
} 
axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels]; 

Tôi thấy nhãn nhưng không có dấu tích nào cả trên x.

+0

Sử dụng mã của bạn ở trên tôi thấy các dấu tích nhưng không phải nhãn. bạn có gợi ý gì không? (@Cesare hỏi) – jjnguy

Trả lời

8

Chỉ cần để đóng câu hỏi này, tôi đã có một câu trả lời từ một trong những kẻ lõi-cốt truyện:

Chỉ cần thiết lập các địa điểm đánh dấu, thêm tuyên bố này:

axisSet.xAxis.majorTickLocations = [NSSet setWithArray:customTickLocations]; 

Kính trọng, Lức

+0

nơi tôi phải thêm dòng này, tôi nhận được lỗi tương tự, tôi đã thêm 5 Nhãn Tôi chỉ có thể thấy 2 nhãn trên màn hình, plz giúp tôi thoát khỏi vấn đề này, tôi đã chi tiêu nhiều thời gian. –

Các vấn đề liên quan