2010-07-08 10 views
6

मुझे यह समस्या लंबे समय से है और मुझे इसे हल करने के लिए कुछ भी नहीं मिला है। मैंने कई फोरम पढ़े लेकिन कामकाजी समाधान नहीं ढूंढ पाए। मेरे पास निम्न कोड है:कोर-प्लॉट: अभी भी समझ में नहीं आता कि कस्टम लेबल कैसे है और

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

मैं लेबल देखता हूं लेकिन एक्स पर बिल्कुल कोई टिक नहीं है।

+0

उपर्युक्त कोड का उपयोग करके मैं टिक देखता हूं लेकिन लेबल नहीं। क्या आपको कोई सुझाव है? (@Cesare ने पूछा) – jjnguy

उत्तर

8

बस इस प्रश्न को बंद करने के मैं कोर-भूखंड लोगों में से एक से एक जवाब था,:,

बस टिक स्थानों निर्धारित करने की आवश्यकता इस बयान को जोड़ने:

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

सादर, ल्यूक

+0

जहां मुझे यह लाइन जोड़नी है, मुझे एक ही त्रुटि मिल रही है, मैंने 5 लेबल जोड़े हैं, मैं स्क्रीन पर केवल 2 लेबल देख सकता हूं, कृपया मुझे इस समस्या से बाहर निकलने में मदद करें, मैंने पहले से ही खर्च किया है काफी समय। –

संबंधित मुद्दे