I want to make a thing like this: http://youtu.be/PeRhxSCx2xM
I try to implement this method:
//viewDidLoad
//plotSpace.delegate = self;
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate {
NSLog(@"WillChangePlotRangeTo");
// only allows scrolling to the right
// remove this to have scrolling in both directions
if (newRange.locationDouble < 0.0F) {
newRange.location = CPTDecimalFromFloat(0.0);
}
// Adjust axis to keep them in view at the left and bottom;
// adjust scale-labels to match the scroll.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
if (coordinate == CPTCoordinateX) {
axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
axisSet.xAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
(newRange.lengthDouble / 2.0F));
} else {
axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
axisSet.yAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
(newRange.lengthDouble / 2.0F));
}
return newRange;
}
And i try this to, this solution works when i zoom-out, but not work when i zoom in.
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];
plotSpace.globalYRange = plotSpace.yRange;
anyone please explain me, what is the correct result, and how its work actually.
Thanks the replies
The easiest way is to just ignore the newRange
and return the existing yRange
for the y-coordinate. You don't need to bother with updating the axis properties here, either. There are easier ways to do that.
// leave the titleLocation for both axes at the default (NAN) to center the titles
xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate {
CPTPlotRange *updatedRange = nil;
switch ( coordinate ) {
case CPTCoordinateX:
if (newRange.locationDouble < 0.0F) {
CPTMutablePlotRange *mutableRange = [[newRange mutableCopy] autorelease];
mutableRange.location = CPTDecimalFromFloat(0.0);
updatedRange = mutableRange;
}
else {
updatedRange = newRange;
}
break;
case CPTCoordinateY:
updatedRange = ((CPTXYPlotSpace *)space).yRange;
break;
}
return updatedRange;
}
I had the similar situation and the problem and it drove me crazy because I forgot to set delegate:
plotSpace.delegate = self;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With