2011-06-01 134 views
1

这是我的代码。没有显示X轴标签。我正在使用核心阴谋。核心图x轴标签未显示

scatterGraph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; 
CPTheme *theme = nil; 
[scatterGraph applyTheme:theme]; 
hostView.hostedGraph = scatterGraph; 
hostView.backgroundColor = [UIColor clearColor]; 
hostView.collapsesLayers = NO; 

scatterGraph.paddingTop = 25.0; 
scatterGraph.paddingRight = 25.0; 
scatterGraph.paddingLeft = 25.0; 
scatterGraph.paddingBottom = 25; 
scatterGraph.plotAreaFrame.masksToBorder = NO; 
CPXYPlotSpace *scatterPlot = (CPXYPlotSpace *) scatterGraph.defaultPlotSpace; 
scatterPlot.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromInt(yCount)]; 
float xx = [self findMax:LivePriceFeedArray] - [self findMin:LivePriceFeedArray]+1.0; 
scatterPlot.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat([self findMin:LivePriceFeedArray]-0.5) length:CPDecimalFromFloat(xx)]; 

CPXYAxisSet *axisSet =(CPXYAxisSet *) scatterGraph.axisSet; 
CPXYAxis *xAxis = axisSet.xAxis; 
axisSet.delegate = self; 
xAxis.title = @"Days"; 
xAxis.titleLocation = CPDecimalFromFloat(4.0f); 
xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(0.0f); 
xAxis.majorIntervalLength = CPDecimalFromFloat(5.0f); 
xAxis.labelingPolicy = CPAxisLabelingPolicyNone; 

NSUInteger labelLocation = 0; 
NSMutableArray *customArray = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]]; 
for (NSNumber *i in customLocations) { 
    CPAxisLabel *iLabel = [[CPAxisLabel alloc] initWithText:[xAxisLabels objectAtIndex:labelLocation++] textStyle:xAxis.labelTextStyle]; 
    iLabel.tickLocation = [i decimalValue]; 
    [customArray addObject:iLabel]; 
    [iLabel release]; 
} 

xAxis.axisLabels = [NSSet setWithArray:customArray]; 
xAxis.majorTickLocations = [NSSet setWithArray:customLocations ]; 
CPLineStyle *majorGridLineStyle = [CPLineStyle lineStyle]; 
xAxis.majorGridLineStyle = [CPLineStyle lineStyle]; 

CPXYAxis *yAxis = axisSet.yAxis; 
yAxis.title = @"Sales Target"; 
yAxis.majorIntervalLength = CPDecimalFromFloat(1.0f); 
yAxis.labelOffset = -5.0f; 
yAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(0.0f); 
CPScatterPlot *graphPlot = [[[CPScatterPlot alloc]init] autorelease]; 
CPMutableLineStyle *lineStyle = [[graphPlot.dataLineStyle mutableCopy] autorelease]; 
lineStyle.lineWidth = 3.0f; 
lineStyle.lineColor = [CPColor whiteColor]; 
graphPlot.dataLineStyle = lineStyle; 
graphPlot.dataSource = self; 
[scatterGraph addPlot:graphPlot]; 
graphPlot.backgroundColor = [UIColor clearColor]; 
CPLineStyle *minorGridLineStyle = majorGridLineStyle; 
xAxis.minorGridLineStyle = minorGridLineStyle; 
yAxis.majorGridLineStyle = majorGridLineStyle; 
yAxis.minorGridLineStyle = minorGridLineStyle; 

为什么不显示x轴标签?

+0

不知道这个,但尝试和调整离开你的图形... ** scatterGraph.paddingLeft = 25.0的填充; **只是尝试和调整 – Krishnabhadra 2011-06-01 06:56:03

+0

Nopes即没有与我的情况下工作...我也尝试填充100。标签不显示...... :( – DivineDesert 2011-06-01 12:36:39

回答

9

我解决了这个问题。正交坐标存在问题。

我解决这样的:

scatterPlot.yRange = [CPPlotRange plotRangeWithLocation: CPDecimalFromFloat (min) length:CPDecimalFromFloat(xx)]; xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(min);

这里plotRangeWithLocation为y轴和orthogonalCoordinateDecimal为x轴应该是相同的。

感谢您的帮助,Krishnabhadra :)

+0

我不知道是谁投了票,但你必须更好地提出一个问题,只是一个标题和一堆代码不会让社区满意,一个问题应该得到答案。 – Krishnabhadra 2011-06-02 05:28:23

+0

你自己也发现了自己的问题(这总是比帮助你的人好),你发布了一个答案,这意味着你重视社区,然后你应该提供更多关于答案的信息,以便帮助他人。 *正交坐标存在问题*没有足够的信息。 – Krishnabhadra 2011-06-02 05:31:09

+0

此外,如果您更新答案,请接受您的答案。您可以接受您自己的答案。这会让其他人知道您已经找到解决问题的办法。 – Krishnabhadra 2011-06-02 05:33:26