0

我有 y 轴和总测试数
和 x 轴时间

以下是我用来绘制的代码:

- (NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {  
    NSUInteger recordplot;  

    if (plot.identifier == @"Plot Error")  
    {  
        recordplot = [HourErroroArray count];  

        recordplot--;  
    }  

    return recordplot;  
}  


- (NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {  
    NSDecimalNumber *num = nil;  
    int eTemp1;  
    int eHour1;  
    int eMin1;  
    int eSec1;  
// Number of the X axis asked  
    if (fieldEnum == CPScatterPlotFieldX)  
    {  

    if (plot.identifier == @"Plot Error")  
        {  
        eHour1=[[HourErroroArray objectAtIndex:index]intValue ];  
        eMin1=[[MinErrorArray objectAtIndex:index]intValue ];  
        eSec1=[[SecErrorArray objectAtIndex:index]intValue ];  

        eTemp1=eHour1*eMin1*eSec1;  

        num = (NSDecimalNumber *)[NSDecimalNumber numberWithInt:eTemp1];  
        }  
    }  
// Number of the Y axis asked  
    else if (fieldEnum == CPScatterPlotFieldY)  
     {   
        if (plot.identifier == @"Plot Error")  
        {  
          num = (NSDecimalNumber *)[NSNumber numberWithInteger:index];  

        }  

     }   

    return num;  

}  

我可以看到图表正在绘制,但仅在一条直线上,即平行于 xaxis

!->y 轴,_ ->x 轴和 . -> 线正在绘制值

y轴  
!  
!   
!............  
!
_____________ x 轴

但我想要以下内容:

http://www.buggyprogrammer.co.uk/2010/10/03/using-core-plot-to-draw-line-graphs/

也许不是上下线,但至少有一些角度。

4

1 回答 1

0

您可能已经切换了 x 和 y 值。您的意思是 y 值是索引,x 值是计算值吗?

否则,插入一些 NSLog 语句-numberForPlot:field:recordIndex:并确保数字(eTemp1、eHour1、eMin1、eSec1)是您所期望的。

[针对评论添加]

检查绘图空间上的绘图范围,以确保它们对您的数据是合理的。如果 y 范围的长度太大,它将压缩绘图,使其看起来像一条水平线。绘图范围的一个常见错误是在创建范围时将长度误认为最终值。CPTPlotRange 的工作方式与 NSRange 相同。作为一个实验,尝试使用绘图空间方法-scaleToFitPlots:让您的数据填充绘图范围。有关示例,请参阅 Mac CPTTestApp。

于 2011-06-14T17:49:29.283 回答