我正在使用核心图并需要反转x轴,使其从5000
开始,到0
结束。我怎么能这样做?
这是我的x轴范围,
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(500)]
答案 0 :(得分:1)
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
希望有所帮助!
答案 1 :(得分:0)
尝试使用以下代码
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0)
length:CPTDecimalFromDouble(5000)]; // Or set it -5000