The main graph disables y-axis scaling, scrolling

I want to do the following: http://youtu.be/PeRhxSCx2xM

I am trying 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'm trying to do this, this solution works when I zoom out, but it doesn't work when I zoom out.

 plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)]; plotSpace.globalYRange = plotSpace.yRange; 

someone please explain to me what the correct result is and how its work really is.

Thanks answers

+4
source share
2 answers

The easiest way is to simply ignore newRange and return the existing yRange for the y coordinate. Here you do not need to worry about updating axis properties. There are simpler ways to do this.

Schedule Setting:

 // 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]; 

Share the delegate:

 - (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; } 
+12
source

I had a similar situation and problem, and it drove me crazy because I forgot to set the delegate:

 plotSpace.delegate = self; 
+1
source

Source: https://habr.com/ru/post/1398969/


All Articles