mrd
mrd

Reputation: 4699

Core Plot: How do I set the x-axis go through zero and at the bottom and y-axis to zero and left?

I am a newbie to CorePlot and finally managed to get some scattered line plot display. How can I set the X-Axis to zero and on the bottom and the Y-Axis to zero and on the left of the graph?

Upvotes: 0

Views: 1176

Answers (2)

Uzer
Uzer

Reputation: 67

Using Swift2:

First, appropriate steps to get to the next statements, then:

let axisSet = graph.axisSet as CPTXYAxisSet
let x = axisSet.xAxis
x.orthogonalPosition = yMin

Further steps to configure x

The same format can be used to get the y crossover if you want it at some other point on your x axis than the first data point you have. Note that if you use dates for your x axis, you will need to use NSDateFormatter based statements to compare the date values.

Upvotes: 0

Jeff Loughlin
Jeff Loughlin

Reputation: 4174

Set the xRange of your plotSpace to

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(xMax)];

and the yRange to

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(yMax)];

where xMax and yMax are the maximum values for your X and Y axis, respectively.

By the default, each axis will be located at the coordinate corresponding to the low end of your plot range - 0.0 if you set your ranges as above. It sounds like this is where you want them, but you can alter the location of the axis if you want to by setting xAxis.orthogonalCoordinateDecimal or yAxis.orthogonalCoordinateDecimal to something other than 0.0, like this:

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(4.0);  // or whatever
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(10.0); // or whatever

Upvotes: 1

Related Questions