Reputation: 42167
I am using core plot to plot about 2000 data points. They load fine, but I only see a smooth line:
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?
Upvotes: 1
Views: 1072
Reputation: 27381
There are a couple of different issues here:
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.
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
Upvotes: 4