简体   繁体   English

修复CorePlot中的轴 - iOS

[英]Fixing Axes in CorePlot - iOS

I am trying to understand how to use CorePlot. 我想了解如何使用CorePlot。 Previously, I used to use google charts to plot my graph. 以前,我曾经使用谷歌图表绘制我的图表。

I am trying to set the axis of my chart to the bottom left and start the 0 from the bottom for both x and y axis. 我试图将我的图表的轴设置为左下角,并从x和y轴的底部开始0。 However, I am unable to understand how the code works. 但是,我无法理解代码是如何工作的。

Here is the code - 这是代码 -

// Setup plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(2.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];

// Axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromString(@"0.5");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2");
x.minorTicksPerInterval = 2;
NSArray *exclusionRanges = [NSArray arrayWithObjects:
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.99) length:CPTDecimalFromFloat(0.02)], 
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.99) length:CPTDecimalFromFloat(0.02)],
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(2.99) length:CPTDecimalFromFloat(0.02)],
    nil];
x.labelExclusionRanges = exclusionRanges;

CPTXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPTDecimalFromString(@"0.5");
y.minorTicksPerInterval = 5;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2");
exclusionRanges = [NSArray arrayWithObjects:
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.99) length:CPTDecimalFromFloat(0.02)], 
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.99) length:CPTDecimalFromFloat(0.02)],
    [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(3.99) length:CPTDecimalFromFloat(0.02)],
    nil];
y.labelExclusionRanges = exclusionRanges;

Would someone be able to tell me what I should do? 有人能告诉我应该怎么做吗?

To start the graph at (0, 0) you need to change the x and y ranges and intersection points. 要在(0,0)处启动图形,您需要更改x和y范围以及交叉点。 You can change this by modifying 您可以通过修改来更改此设置

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(2.0)];

to

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

and also change the plotRangeWithLocation to 0 for the yRange. 并且还将yRange的plotRangeWithLocation更改为0。

Also, you need to change this 此外,您需要更改此设置

x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2");

to

x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");

and do the same for orthogonalCoordinateDecimal of y. 并对y的orthogonalCoordinateDecimal执行相同的操作。

NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setGeneratesDecimalNumbers:NO];

axisSet = (CPTXYAxisSet *)graph.axisSet;

x_axis = axisSet.xAxis;
x_axis.majorIntervalLength = CPTDecimalFromString(@"1");
x_axis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x_axis.minorTicksPerInterval = 0;
x_axis.labelFormatter = numberFormatter;

 axisSet.xAxis.visibleRange =[CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(100)]; // you can set your number instead of 100
 axisSet.xAxis.gridLinesRange = axisSet.xAxis.visibleRange;

y_axis = axisSet.yAxis;
y_axis.majorIntervalLength = CPTDecimalFromString(@"1");
y_axis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y_axis.minorTicksPerInterval = 1;
y_axis.labelFormatter = numberFormatter;

axisSet.yAxis.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(100)]; // you can set your number instead of 100
axisSet.yAxis.gridLinesRange = axisSet.yAxis.visibleRange;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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