使用核心图绘制折线图时出现的问题
我的 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;
}
我可以看到图形正在绘制,但只是在一条直线上,即平行于 x 轴
!->y 轴、_ ->x 轴和 。 ->line 正在绘制值
y-axis ! ! ! ........... ! ______________ x-axis
,但我想要如下所示的内容:
http://www.buggyprogrammer.co.uk/2010/10/03/using-core-plot-to-draw-line-graphs/
也许没有-和沿着线,但至少有一定的角度。
I have y axis with numbers of total test
and x axis for time
The following is the code I am using to plot:
- (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;
}
I can see the graph is plotting but only in a straight line i.e. parallel to xaxis
!->y-axis, _ ->x-axis and . ->line is plotting for values
y-axis ! ! ! ........... ! ______________ x-axis
but I want something like the following:
http://www.buggyprogrammer.co.uk/2010/10/03/using-core-plot-to-draw-line-graphs/
Maybe not up-and down lines, but at least with some angle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能交换了 x 和 y 值。您的意思是 y 值是索引,x 值是计算值吗?
否则,在
-numberForPlot:field:recordIndex:
中插入一些 NSLog 语句,并确保数字(eTemp1、eHour1、eMin1、eSec1)符合您的预期。[针对评论添加]
检查绘图空间上的绘图范围,以确保它们对于您的数据来说是合理的。如果 y 范围的长度太大,它会压缩绘图,使其看起来像水平线。绘图范围的一个常见错误是在创建范围时将长度误认为是最终值。 CPTPlotRange 的工作方式与 NSRange 相同。作为实验,尝试使用绘图空间方法
-scaleToFitPlots:
让数据填充绘图范围。有关示例,请参阅 Mac CPTTestApp。You may have switched the x and y values. Did you mean for the y value to be the index and the x value be the calculated value?
Otherwise, insert some NSLog statements in
-numberForPlot:field:recordIndex:
and make sure the numbers (eTemp1, eHour1, eMin1, eSec1) are what you expect.[added in response to the comments]
Check your plot ranges on the plot space to make sure they're reasonable for your data. If the length of the y range is too large, it will compress the plot so it looks like a horizontal line. A common mistake with plot ranges is mistaking the length for the end value when creating the range. CPTPlotRange works the same way as NSRange. As an experiment, try using the plot space method
-scaleToFitPlots:
to have your data fill the plot range. See the Mac CPTTestApp for an example.