Problem:
Lets say I have a equation:
y = x^2
Using core-plot I doing this:
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return 3000;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSNumber *num = nil;
switch ( fieldEnum ) {
case CPTScatterPlotFieldX:
num = [NSNumber numberWithUnsignedInteger:index];
break;
case CPTScatterPlotFieldY:
num = [NSNumber numberWithUnsignedInteger:index*index];
break;
}
return num;
}
But this will draw only 3000 points, even after zoom-out (when X-axis shows points from 0 to 5000). So rest of the area undrawn.
What I want is: after zoom-out, I can refresh the plot in full visible area.
Anybody know how to do it?
First of all, I would limit the number of points to no more than the number of pixels available to draw the plot. Any more than that just takes more time to draw for no visible benefit. Look at the size of the plot area bounds to get the dimensions of the drawing area. Multiply the width and height by the
contentsScaleif you might be running on a device with a Retina display.You can use a plot space delegate to find out when the user zooms or scrolls the graph. Call
reloadDataon the plot inside your delegate method to recalculate the plot data.