这是我的代码。 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 :(得分:9)
我解决了这个问题。正交坐标存在问题。
我解决了这个问题:
scatterPlot.yRange = [CPPlotRange plotRangeWithLocation: CPDecimalFromFloat (min) length:CPDecimalFromFloat(xx)];
xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(min);
这里y轴的plotRangeWithLocation和x轴的orthogonalCoordinateDecimal应该是相同的。
感谢你的帮助,Krishnabhadra:)