开发者

in core-plot, how do I get my axes to float?

I've tried setting isFloatingAxis to YES, but it just makes my axis disappear. My axis is set up as follows:

CPXYAxisSet *axisSetKin = (CPXYAxisSet *)kinematicsGraph.axisSet;
CPXYAxis *xKin = axisSetKin.xAxis;
[x开发者_Go百科Kin setIsFloatingAxis:YES];
xKin.labelingPolicy = CPAxisLabelingPolicyAutomatic;
xKin.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
xKin.minorTicksPerInterval = 4;
xKin.preferredNumberOfMajorTicks = 9;
xKin.majorGridLineStyle = majorGridLineStyleKin;
xKin.minorGridLineStyle = minorGridLineStyleKin;
xKin.labelOffset = 10.0;
xKin.title = @"Lab Angle";
xKin.titleOffset = 30.0;
xKin.titleLocation = CPDecimalFromString(@"2.7");

Any ideas?


I too have been playing with the demo applications getting the plots to do what I need. Using CPTestApp-Iphone as a base I started playing with CPTestAppScatterPlotController.m

First I did:

y.isFloatingAxis = YES;
x.isFloatAxis = YES;

After hitting "Run" it seemed like the axis disappeared, but they are still there if you look closely. On the lefthand side and bottom of the screen the tick marks are there, just very hard to see.

To see the labels we need to add some extra padding. Notice towards the top of CPTestAppScatterPlotController.m we set some padding for the graph itself:

graph.paddingLeft = 10.0;
graph.paddingTop = 10.0;
graph.paddingRight = 10.0;
graph.paddingBottom = 10.0;

If we add:

graph.plotAreaFrame.paddingLeft = 30.0;
graph.plotAreaFrame.paddingBottom = 30.0;

One can get the labels to appear.


https://github.com/djw/core-plot/tree/9282845bddbb8c40ff314bbfa158beff797c91f7/examples

This states that the isFloatingAxis property has been removed from at least version 0.9.

I found issue 108 addresses this as well, and gives a place to see how CorePlot is handling the change: http://code.google.com/p/core-plot/issues/detail?id=108

It seems like the new way to float an axis is to set its constraints:

x.axisConstraints = [CPTConstraints constraintWithUpperOffset:132];


Ok, it looks like having constraints is the key. So I should have

CPConstraints y2Constraints = {CPConstraintFixed, CPConstraintFixed};
    yKin.isFloatingAxis = YES;
    yKin.constraints = y2Constraints;

in there as well. If you use CPConstraintNone instead, then the axis will actually move around as you resize the view that it's sitting in, to the point that it may appear to not be there at all when the program first starts. fixed keeps it in place. Now to figure out how to position it...

Oh, and another bit that's necessary to know: the axes, when set to float, can show up outside of the normal plot space. you can tweak exactly where by modifying the origin with, for example,

    xKin.orthogonalCoordinateDecimal = CPDecimalFromString(@"0.5");

I'm not sure exactly what the units are for this, so you may have to play around with the numbers to find the one you want.

In the case that you want the axes to appear on the bottom and left side of the plot, and stay there, you have one more thing to do. Because you are setting the position to 0, using the .orthogonalCoordinateDecimal trick above, they will actually show up outside the plot space, and thus appear to have vanished. This was the case with my program when I first set setIsFloatingAxis:YES. To fix this, you have to add some padding to the plotAreaFrame. Note that this is different from the padding seen in the main section of CPTestApp, which goes [graph setPaddingLeft:0]; Instead, use graph.plotAreaFrame.paddingTop = 20.0; (or equivalently, [[graph plotAreaFrame] setPaddingTop: 20.0];

Full examples of that can be found in CPTestApp's AxisDemoController.m.

So I guess I kinda answered my own question here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜