将核心图 x 轴移动到最后一点

发布于 2024-12-07 22:39:51 字数 216 浏览 0 评论 0原文

我的 iPhone 应用程序中的核心绘图绘制得很好。然而,有一件事我似乎无法弄清楚。如何让图表在视图加载后滚动到 x 轴的末尾,而不是从原点开始?我希望当图表出现时,x 轴上的最后一个数据点可见。如何?

我看到了plotSpace:willDisplaceBy:委托方法,它“接近”我所需要的,但我需要能够告诉图形在加载视图时将其自身移动到x轴的末端。我还没有找到任何相关的核心图示例代码来执行此操作。

My core plot graph in my iPhone app is drawing nicely. However, one thing I can't seem to figure out. How can I get the graph to scroll to the end of its x axis after the view loads, rather than starting at the origin? I would like the last data point upon the x axis to be visible when the graph appears. How?

I saw the plotSpace:willDisplaceBy: delegate method, which is "close" to what I need, but I need to be able to tell the graph to displace itself to the end of its x axis when its view loads. I haven't found any relevant example code for core plot to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛徒 2024-12-14 22:39:51

您需要设置绘图空间的xRange,以便最后一个点可见。如果您知道结束值和希望可见的范围的长度,则可以执行以下操作:

CPTXYPlotSpace *plotSpace = graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange rangeWithLocation:CPTDecimalFromDouble(end - length)
                                            length:CPTDecimalFromDouble(length)];

该示例假设所需的长度为正数,并且您的值是双精度数。如果需要,您当然可以使用 NSDecimal 值进行计算。

You need to set the xRange of the plot space so that the last point is visible. If you know the ending value and the length of the range you want to be visible, you can do something like this:

CPTXYPlotSpace *plotSpace = graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange rangeWithLocation:CPTDecimalFromDouble(end - length)
                                            length:CPTDecimalFromDouble(length)];

The example assumes that the desired length is positive and your values are doubles. You can of course do the calculations using NSDecimal values if needed.

深海少女心 2024-12-14 22:39:51

使用这个方法:

-(CPPlotRange *)plotSpace:(CPPlotSpace *)space willChangePlotRangeTo:(CPPlotRange *)newRange forCoordinate:(CPCoordinate)coordinate
{
    if (coordinate == CPCoordinateY) {
        CPPlotRange *maxRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(6.0f)];
        CPPlotRange *changedRange = [[newRange copy] autorelease];
        [changedRange shiftEndToFitInRange:maxRange];
        [changedRange shiftLocationToFitInRange:maxRange];
        newRange =  changedRange;
    }
    return newRange;

}

use this method :

-(CPPlotRange *)plotSpace:(CPPlotSpace *)space willChangePlotRangeTo:(CPPlotRange *)newRange forCoordinate:(CPCoordinate)coordinate
{
    if (coordinate == CPCoordinateY) {
        CPPlotRange *maxRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(6.0f)];
        CPPlotRange *changedRange = [[newRange copy] autorelease];
        [changedRange shiftEndToFitInRange:maxRange];
        [changedRange shiftLocationToFitInRange:maxRange];
        newRange =  changedRange;
    }
    return newRange;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文