我正在使用 core-plot,需要反转 x 轴,使其从 5000
开始并在 0
结束。我该怎么做?
这是我的 x 轴范围,
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(500)]
最佳答案
Plot Gallery 应用程序(Plot Space Demo)中有一个这样的例子。如果查看 PlotSpaceDemo.m 中的相应代码,负轴设置如下:
...
CPTXYPlotSpace *negativeLinearPlotSpace = [[[CPTXYPlotSpace alloc] init] autorelease];
negativeLinearPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(100) length:CPTDecimalFromInteger(-100)];
negativeLinearPlotSpace.yRange = linearPlotSpace.yRange;
[graph removePlotSpace:graph.defaultPlotSpace];
[graph addPlotSpace:negativeLinearPlotSpace];
CPTXYAxis *negativeLinearAxis = [[[CPTXYAxis alloc] init] autorelease];
negativeLinearAxis.plotSpace = negativeLinearPlotSpace;
//The rest of the set up is just formatting labels, ticks, etc.
...
因此对于您的情况,您可以像这样用 5000 和 -5000 的长度声明位置:
negativeLinearPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(5000) length:CPTDecimalFromInteger(-5000)];
//Add plot space to the graph
//assign plot space to the x axis
希望对您有所帮助!
关于ios - 如何反转x轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22553396/