IOS CorePlot Dock Vertical Axis


/ Published in: iPhone
Save to your folder(s)

Begin by making the class a CPPlotSpaceDelegate.


Copy this code and paste it in your HTML
  1. // in the viewDidLoad Method:
  2. // CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
  3. // plotSpace.delegate = self;
  4.  
  5. /*
  6.  * "Dock" the Y-axis and only allow horizontal scrolling toward the right.
  7.  */
  8. - (CPPlotRange *)plotSpace:(CPPlotSpace *)space
  9. willChangePlotRangeTo:(CPPlotRange *)newRange
  10. forCoordinate:(CPCoordinate)coordinate {
  11.  
  12. NSLog(@"WillChangePlotRangeTo");
  13.  
  14. // only allows scrolling to the right
  15. // remove this to have scrolling in both directions
  16. if (newRange.locationDouble < 0.0F) {
  17. newRange.location = CPDecimalFromFloat(0.0);
  18. }
  19.  
  20. // Adjust axis to keep them in view at the left and bottom;
  21. // adjust scale-labels to match the scroll.
  22. CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
  23. if (coordinate == CPCoordinateX) {
  24. axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
  25. axisSet.xAxis.titleLocation = CPDecimalFromFloat(newRange.locationDouble +
  26. (newRange.lengthDouble / 2.0F));
  27. } else {
  28. axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
  29. axisSet.yAxis.titleLocation = CPDecimalFromFloat(newRange.locationDouble +
  30. (newRange.lengthDouble / 2.0F));
  31. }
  32.  
  33. return newRange;
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.