核心图:在iOS上显示右对齐的Y轴

时间:2012-08-16 22:19:28

标签: objective-c ios core-plot

我现在已经搜索了很长时间,并且发现了大量的旧资源,这些资源曾一度为我当前的问题提供解决方案。但是,Core Plot已经发展,如果以相同的方式实现,我发现的解决方案将不再起作用。我希望能得到最新的答案,我确信这是各种图表和图表的共同特征。

我当前的问题是,当我尝试右对齐我的情节中的3个轴中的一个,而轴本身,包括标题,确实移动,没有刻度线或相关标签。我猜我的东西可能不完整。

这是我的相关轴生成代码:

CPTAxis *yRight = [[CPTXYAxis alloc] init];
yRight.Title = @"Right Axis";
yRight.titleOffset = 10.0f;
yRight.axisLineStyle = axisLineStyle;
yRight.majorTickLineStyle = axisLineStyle;
yRight.minorTickLineStyle = axisLineStyle;
yRight.labelTextStyle = axisTextStyle;
yRight.labelOffset = 3.0f;
yRight.majorIntervalLength = CPTDecimalFromFloat(10.0f);
yRight.minorTicksPerInterval = 5;
yRight.minorTickLength = 5.0f;
yRight.majorTickLength = 7.0f;

axisSet.axes = [NSArray arrayWithObjects:x, yRight, yLeft, nil];
self.hostView.hostedGraph.axisSet = axisSet;

//Next two lines are in charge of right aligning y axis
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithUpperOffset:0];
//axisSet.yAxis.tickDirection = CPTSignPositive; this is commented out because I havent found it to do anything, though may be necessary for it to work once complete.

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)hostView.hostedGraph.defaultPlotSpace;
x.plotSpace = plotSpace;
yLeft.plotSpace = plotSpace;
yRight.plotSpace = plotSpace;

我觉得我所缺少的并不是很多,但我已经完成了关于寻找什么的想法并尝试了。

迷你方面的问题,iOS支持浮动轴吗? axisSet.yAxis.isFloatingAxis给了我一个错误:(

感谢您提供任何帮助!

1 个答案:

答案 0 :(得分:1)

删除isFloatingAxis属性以支持轴约束。

yRight.axisConstraints = [CPTConstraints constraintWithUpperOffset:0];
yRight.coordinate = CPTCoordinateY;

情节空间的yRange是多少?当前的标签设置会将标记和标签放在yRight上的0,10,20等处。