简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM