核心图生成一条平线,X 或 Y 范围不正确?

发布于 2024-10-05 02:21:09 字数 801 浏览 0 评论 0原文

我正在使用核心图绘制大约 2000 个数据点。它们加载良好,但我只看到一条平滑的线:

alt text

我不知道为什么它只是一条平坦的线而不是显示我在大范围内的所有值的图表。我在设置绘图空间时做错了什么吗?

CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = NO;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(num_points)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(num_points)];

这也是我的 numberForPlot 方法:

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSNumber *num = [sortedArray objectAtIndex:index];
    return num;
}

知道我在这里做错了什么吗?

I am using core plot to plot about 2000 data points. They load fine, but I only see a smooth line:

alt text

I am not sure why it is just a flat line rather than showing a graph of all of my values which are in a large range. Have I done something wrong with setting up the plot space?

CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = NO;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(num_points)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(num_points)];

Here is my numberForPlot method as well:

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSNumber *num = [sortedArray objectAtIndex:index];
    return num;
}

Any ideas what I am doing wrong here?

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

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

发布评论

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

评论(1

夏の忆 2024-10-12 02:21:09

这里有几个不同的问题:

  1. 绘图空间范围以数据坐标给出。您可以自己计算范围,也可以使用绘图空间方法 -scaleToFitPlots: 自动计算范围。查看我对您的相关问题的回答在核心图讨论板上了解如何手动计算范围。

  2. 您的-numberForPlot:field:recordIndex:忽略field参数。您为 CPScatterPlotFieldXCPScatterPlotFieldY 返回相同的值,因此是对角线。

一种可能的解决方案:

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSNumber *num = nil;

    switch ( fieldEnum ) {
    case CPScatterPlotFieldX:
        num = [NSNumber numberWithUnsignedInteger:index];
        break;
    case CPScatterPlotFieldY:
        num = [sortedArray objectAtIndex:index];
        break;
    }

    return num;
}

埃里克

There are a couple of different issues here:

  1. The plot space ranges are given in data coordinates. You can either calculate the ranges yourself or use the plot space method -scaleToFitPlots: to calculate them automatically. See my answer to your related question on the Core Plot discussion board for how to calculate the ranges manually.

  2. Your -numberForPlot:field:recordIndex: ignores the field parameter. You're returning the same value for both CPScatterPlotFieldX and CPScatterPlotFieldY, hence the diagonal line.

One possible solution:

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSNumber *num = nil;

    switch ( fieldEnum ) {
    case CPScatterPlotFieldX:
        num = [NSNumber numberWithUnsignedInteger:index];
        break;
    case CPScatterPlotFieldY:
        num = [sortedArray objectAtIndex:index];
        break;
    }

    return num;
}

Eric

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