Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Coreplot/Xcode帮助:在保持可见X轴的同时放大栅格区域_Objective C_Xcode_Core Plot - Fatal编程技术网

Objective c Coreplot/Xcode帮助:在保持可见X轴的同时放大栅格区域

Objective c Coreplot/Xcode帮助:在保持可见X轴的同时放大栅格区域,objective-c,xcode,core-plot,Objective C,Xcode,Core Plot,我本来打算提供我的核心绘图图的屏幕截图供参考,但我还不允许(新用户),所以我可以根据要求发送电子邮件 我有一组数据点,x值为1到150,y值为300到450。 我想做的是绘制这些点,用一个干净的网格覆盖,放大图像 y轴(图形y轴应从y最小值开始,而不是从0开始,然后转到y最大值),同时仍保留可见的x轴以供参考 我已经接近实现我想要的目标,但我仍在为一些事情而挣扎 首先,我想在y轴上y轴和x轴之间的交点处以及y轴顶部添加一个标签,以便为用户提供一个参考点 为了实现这一点,我开始使用主要的刻度间隔,

我本来打算提供我的核心绘图图的屏幕截图供参考,但我还不允许(新用户),所以我可以根据要求发送电子邮件

我有一组数据点,x值为1到150,y值为300到450。 我想做的是绘制这些点,用一个干净的网格覆盖,放大图像 y轴(图形y轴应从y最小值开始,而不是从0开始,然后转到y最大值),同时仍保留可见的x轴以供参考

我已经接近实现我想要的目标,但我仍在为一些事情而挣扎

首先,我想在y轴上y轴和x轴之间的交点处以及y轴顶部添加一个标签,以便为用户提供一个参考点

为了实现这一点,我开始使用主要的刻度间隔,并在数据集上运行一些操作来确定最大和最小值。但是,当我尝试放大时(即聚焦于y-min和y-max之间的范围),x轴不再可见

为了解决这个问题,我在网上搜索了几次后发现:

axisSet.xAxis.axisConstraints=[CPTCConstraints Constraints ConstraintWithLowerofSet:0]

虽然这似乎迫使x轴出现,但它似乎也让我的图表偏离了一点。。。在我的第一个y轴主刻度和原点之间只有3个小刻度,原点上没有y轴标签

是否有人知道如何实现此偏移,同时强制原点成为第一个主刻度,并在原点和y-Max处显示y轴的标签

作为一个附带问题,是否有人知道如何将x轴标签显示为整数而不是浮点数(希望切掉小数)

我将在下面介绍我迄今为止所取得的成就的源代码

谢谢

布兰登

初始化绘图的源代码:

-(无效)初始值{

[self setDataMaxAndMins];

// Create a graph object which we will use to host just one scatter plot.
CGRect frame = [self.hostingView bounds];
self.graph = [[CPTXYGraph alloc] initWithFrame:frame];

// Add some padding to the graph, with more at the bottom for axis labels.
self.graph.plotAreaFrame.paddingTop = 50.0f;
self.graph.plotAreaFrame.paddingRight = 50.0f;
self.graph.plotAreaFrame.paddingBottom = 100.0f;
self.graph.plotAreaFrame.paddingLeft = 120.0f;

// Tie the graph we've created with the hosting view.
self.hostingView.hostedGraph = self.graph;

self.hostingView.backgroundColor = [UIColor blackColor];

// Create a line style that we will apply to the axis
CPTMutableLineStyle *axisStyle = [CPTMutableLineStyle lineStyle];
axisStyle.lineColor = [CPTColor grayColor];
axisStyle.lineWidth = 2.0f;


CPTColor * customGray = [CPTColor colorWithComponentRed:0.6f green: 0.6f blue: 0.6f alpha: 1.0f];
CPTMutableLineStyle *gridStyle = [CPTMutableLineStyle lineStyle];
gridStyle.lineColor = customGray;
gridStyle.lineWidth = 2.0f;

//Create plot symbol style
CPTMutableLineStyle * plotStyle = [CPTMutableLineStyle lineStyle];
plotStyle.lineColor = [CPTColor whiteColor];
plotStyle.lineWidth = 2.0f;

// Create a text style that we will use for the axis labels.
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.fontName = @"Helvetica";
textStyle.fontSize = 20;
textStyle.color = [CPTColor whiteColor];

// Create the plot symbol we're going to use.
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.lineStyle = plotStyle;
plotSymbol.size = CGSizeMake(3.0, 3.0);
//plotSymbol.


// Setup some floats that represent the min/max values on our axis.
float xAxisMin = xMin;
float xAxisMax = xMax + 5;
float yAxisMin = yMin;
float yAxisMax = yMax + 5;

// We modify the graph's plot space to setup the axis' min / max values.
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];

// Modify the graph's axis with a label, line style, etc.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;

axisSet.xAxis.title = xAxisTitle;
axisSet.xAxis.titleTextStyle = textStyle;
axisSet.xAxis.titleOffset = 50.0f;
axisSet.xAxis.axisLineStyle = axisStyle;
axisSet.xAxis.majorTickLineStyle = axisStyle;
axisSet.xAxis.minorTickLineStyle = axisStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat((xAxisMax - xAxisMin) / 4);//CPTDecimalFromFloat(25.0f);
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;


axisSet.yAxis.title = [yAxisTitle stringByAppendingString: @" ($M)"];

axisSet.yAxis.titleTextStyle = textStyle;
axisSet.yAxis.titleOffset = 80.0f;
axisSet.yAxis.axisLineStyle = axisStyle;
axisSet.yAxis.majorTickLineStyle = axisStyle;
axisSet.yAxis.minorTickLineStyle = axisStyle;
axisSet.yAxis.labelTextStyle = textStyle;
axisSet.yAxis.labelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = CPTDecimalFromFloat((yAxisMax - yAxisMin) / 4);
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;

CPTColor * customLighterBlue = [CPTColor colorWithComponentRed:0.0f green: 0.0f blue: 0.4f alpha: 1.0f];
CPTColor * customDarkBlue = [CPTColor colorWithComponentRed:0.0f green: 0.0f blue: 0.3f alpha: 1.0f];
axisSet.xAxis.alternatingBandFills = [NSArray arrayWithObjects:customLighterBlue, customDarkBlue, nil];

axisSet.xAxis.majorGridLineStyle = gridStyle;

axisSet.yAxis.majorGridLineStyle = gridStyle;

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];


// Add a plot to our graph and axis. We give it an identifier so that we
// could add multiple plots (data lines) to the same graph if necessary.
CPTScatterPlot *plot = [[CPTScatterPlot alloc] init];
plot.dataSource = self;
plot.identifier = @"mainplot";
plot.dataLineStyle = nil;
plot.plotSymbol = plotSymbol;
[self.graph addPlot:plot];

//[_graph.defaultPlotSpace scaleToFitPlots:[_graph allPlots]];
}

  • 更改标签策略。我认为
    CPTAxisLabelingPolicyEqualDivisions
    会满足您的需求。Plot Gallery示例应用程序中有一个演示,显示了所有可用的标签策略

  • 在x轴上设置
    labelFormatter
    。这是一个标准


  • 我让标签格式化程序正常工作,谢谢你的提醒。我查看了为CPTAxisLabelingPolicyEqualDivisions发布的演示,但是在实现它时遇到了问题。。。如果我将x轴和y轴标签策略设置为此,我将完全丢失交替带,并且只获得x轴和y轴最大值的网格线。。。基本上,该策略似乎只是将我的图形转换为一个区域(x和y最大值为1个大刻度,中间为4个小刻度)。我希望保留区域的数量(由主刻度处的交替带和网格线定义),我开始更好地隔离问题。基本上,我的x轴(以及随后的主刻度网格线)是好的,因为我以(xmax xmin)/4的间隔生成主刻度,这确保最后一个主刻度(以及最后一条网格线)落在图形的边缘,很好地装箱。我对yAxis使用了类似的技术,但是遇到了麻烦,因为我正在偏移我的xAxis,所以第一个主刻度不会落在新偏移的xAxis上(刻度仍然从0开始),因此我的网格线最终处于一个奇怪的位置。有什么想法吗?解决了。谢谢你,埃里克,你是一个核心剧情英雄:)。使用CPTAxisLabelingPolicyEqualDivisions是解决方案的一半,另一半是设置axisSet.yAxis.preferredNumberOfMajorTicks。。。美丽的。干杯