【问题标题】:Core plot x-axis labels are not shown核心图 x 轴标签未显示
【发布时间】:2011-06-01 04:57:45
【问题描述】:

这是我的代码。 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 轴标签?

【问题讨论】:

  • 不确定,但尝试调整图表左侧的填充... scatterGraph.paddingLeft = 25.0; 尝试调整
  • 不,这不适用于我的情况......我也尝试使用填充 100。标签不显示... :(

标签: iphone core-plot


【解决方案1】:

我解决了这个问题。直角坐标有问题。

我是这样解决的:

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

这里y轴的plotRangeWithLocation和x轴的正交CoordinateDecimal应该是一样的。

感谢您的帮助,克里希纳巴德拉 :)

【讨论】:

  • 我不知道谁对你投了反对票。但你必须更好地提出问题。只是一个标题和一堆代码不会取悦社区。一个问题应该有一个答案。
  • 您自己发现问题也很好(这总是比有人帮助您好)。您发布了答案,这意味着您重视社区。然后,您应该提供有关您的答案的更多信息,以便它可以帮助其他人。 直角坐标有问题信息不足..
  • 另外,如果您更新答案,请接受您的答案。您可以接受您自己的答案。这会让其他人知道您已经找到了问题的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多