【问题标题】:Problem in line chart plotting with core plot使用核心图绘制折线图的问题
【发布时间】:2011-06-14 15:48:37
【问题描述】:

我的 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/

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

【问题讨论】:

    标签: ios graph charts core-plot linechart


    【解决方案1】:

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

    否则,请在 -numberForPlot:field:recordIndex: 中插入一些 NSLog 语句,并确保数字(eTemp1、eHour1、eMin1、eSec1)符合您的预期。

    [为回应 cmets 而添加]

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

    【讨论】:

    • 是的,你是对的 x 轴将包含计算值,y 轴将包含索引,因为应该绘制索引增加线但这种情况不会发生,在调试时我也会检查 x 轴值及其很好....但我仍然不知道如何解决这个问题
    • 绘制了多少数据点?此外,请检查绘图空间上的绘图范围,以确保它们对您的数据是合理的。如果 y 范围的长度太大,它会压缩绘图,使其看起来像一条水平线。
    • 你是对的,Eric,如果我减少 y 轴值,那么我可以看到几条 zic-zac 线而不是水平线,但这仍然不是我需要的正确...你认为也必须x轴,我计算x轴如下:x轴包含秒(小时分钟秒)
    • 我也用 Hour*Min 尝试了 xaxis,然后它给 min zic-zac 提供了改进的一个,但它仍然不是曲线或天使线随着 x 和 y 轴的增加
    • 绘图范围的一个常见错误是在创建范围时将length 误认为是最终值。 CPTPlotRange 的工作方式与 NSRange 相同。确保您的绘图范围正确。作为一个实验,尝试使用绘图空间方法-scaleToFitPlots: 让您的数据填充绘图范围。有关示例,请参见 Mac CPTTestApp。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    相关资源
    最近更新 更多