简体   繁体   English

核心情节不是scalling

[英]core-plot not scalling

I cannot get my graph with all the plot points to fit in my view. 我无法获得包含所有绘图点的图表以适合我的视图。

在此输入图像描述 The coordinates being displayed in the screen shot above are: x=1, y=10 and x=2, y=0 . 上面屏幕截图中显示的坐标是: x=1, y=10 and x=2, y=0

This is a screenshot of my UIViewController ( GraphingViewController ) I have a separate view nested within here that is the host view for the graph. 这是我的UIViewControllerGraphingViewController )的截图我在这里嵌套了一个单独的视图,它是图形的主机视图。 My code for the graph is exactly the same as SimpleScatterPlot.m with the exception of the generate data method which I have customized: 我的图形代码与SimpleScatterPlot.m完全相同,但我自定义的生成数据方法除外:

-(void)generateData
{
    NSMutableArray *contentArray = [NSMutableArray array];
    int counter = 0;
    for (NSNumber * entryValue in self.plotDataArray) {
        counter++;
        id x = [NSDecimalNumber numberWithInt:counter];
        id y = [NSDecimalNumber numberWithInt:[entryValue intValue]];
        [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
        NSLog(@"setting values for graph x: %@ and y: %@",x,y);
    }
    plotData = [contentArray retain];
}

Another thing that is strange is that I can scroll left and right but not up or down. 另一件奇怪的事情是我可以向左和向右滚动但不能向上或向下滚动。 I have in prior changes had the x,y start at 0,0 but that hides the x axis, so although its what I want, I cant have that line hidden. 我在先前的更改中x,y从0,0开始,但隐藏了x轴,所以虽然它是我想要的,但我不能隐藏该行。

How can I start the graph at 0,0 and be able to scale it to not only see all points but also to see the labels (" X Axis ", " Y Axis ")? 如何在0,0开始图形并且能够将其缩放到不仅可以看到所有点而且还能看到标签(“ X Axis ”,“ Y Axis ”)? Also the Y axis is going by .2 and X by .5 as you can see. 如你所见,Y轴也是.2 ,X是.5 These should be 1 as all of my numbers would be whole numbers. 这些应该是1因为我的所有数字都是整数。

The way I implemented it is the same way. 我实现它的方式是一样的。 I keep track of the min and max X and Y values from the data, and then set the plot range accordingly. 我跟踪数据中的最小和最大X和Y值,然后相应地设置绘图范围。

// Adjust the plot space according to the min and max x/y values
plotSpace.xRange = [[CPTPlotRange alloc] initWithLocation:CPTDecimalFromInt([self.minTime intValue]) length:CPTDecimalFromInt ([self.maxTime intValue] - [self.minTime intValue])];
plotSpace.yRange = [[CPTPlotRange alloc] initWithLocation:CPTDecimalFromInt([self.minScore intValue]) length:CPTDecimalFromInt (([self.maxScore intValue] - [self.minScore intValue]))];

The easy way to keep the axis labels visible is to not set the titleLocation . 保持轴标签可见的简单方法是设置titleLocation The default value of NAN will position the label in the center of the plot area. NAN的默认值将标签定位在绘图区域的中心。

The globalYRange is preventing vertical scrolling. globalYRange阻止垂直滚动。 The default value of nil does not limit scrolling. 默认值nil不限制滚动。 If you do want limit scrolling, but need to change the plot range to show new data, set the global range to nil , update the plot range, and reset the global range. 如果确实需要限制滚动,但需要更改绘图范围以显示新数据,请将全局范围设置为nil ,更新绘图范围并重置全局范围。

The tick locations and axis labels are controlled by the axis labeling policy. 刻度线位置和轴标签由轴标签策略控制。 The default fixed interval policy will work, just leave the majorIntervalLength at the default value of one (1). 默认的固定间隔策略将起作用,只需将majorIntervalLength为默认值one(1)即可。

你尝试过scaleToFitPlots方法吗?

 [plotSpace scaleToFitPlots:[NSArray arrayWithObjects:scatterPlot, nil]];

I fixed one part of the problem which was that the high points where not being shown. 我解决了问题的一部分,即未显示的高点。 This line of code was limiting the max Y Axis 这行代码限制了最大Y Axis

CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)
                                                          length:CPTDecimalFromFloat(2.0f)];

So I created a property to keep track of the largest value and set this to that: 所以我创建了一个属性来跟踪最大值并将其设置为:

CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)
                                                          length:CPTDecimalFromFloat(self.largestYvalue)];

So now I have this: 所以现在我有这个:

在此输入图像描述

I still need to figure out how to get X Axis label to show (Ill update If I figure it out or still accepting answers for that). 我仍然需要弄清楚如何显示X Axis标签(生病更新如果我弄明白或仍然接受答案)。

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

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