I am trying to change to core plot’s majorIntervalScale while I’m zooming so as less items appear on the axis when zooming out and more appear when zooming in. I can’t get this to work can anyone help please? Here’s the code that I got so far. Thanks
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint
{
return YES;
}
-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
self.graphScaleX = self.graphScaleX*newRange.lengthDouble;
self.graphScaleY = self.graphScaleY*newRange.lengthDouble;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
CPTXYAxis *y = axisSet.yAxis;
x.majorIntervalLength=CPTDecimalFromFloat(self.graphScaleX);
y.majorIntervalLength=CPTDecimalFromFloat(self.graphScaleY);
return newRange;
}
It looks like you always want to have the same number of tick marks no matter the length of the plot range. If so, use a different axis labeling policy instead of a delegate. The
CPTAxisLabelingPolicyAutomaticpolicy will find tick marks on “nice” numbers, but not necessarily the ends of the plot range. TheCPTAxisLabelingPolicyEqualDivisionswill place equally-spaced ticks starting at one end of the plot range and continuing to the other. Both of these labeling policies use thepreferredNumberOfMajorTicksto control how many tick marks to draw.