1
votes

I'm working on a graph displaying dates on the x-axis, and percent on the y-axis (1-100). I have got the graph to show kind of the way I like, but I want to disable the ability to scroll and scale the graph in y-direction, so the values 1-100 always is displayed at the same scale. However, I cannot disable user interaction completely, as I want the user to be able to scroll (and perhaps scale) in the x-direction as the number of dates gets bigger, and touch the nodes to display values.

I was able to to this in s7graphview, which I was using before, but haven't been able to get this to work with iOS 5. Also, the smooth scrolling I got from the scrollView in s7 had been fine to have in Core Plot :)

2

2 Answers

3
votes
//for stop vertical scrolling

-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement{
        return CGPointMake(displacement.x,0);}


-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate{
    if (coordinate == CPTCoordinateY) {
        newRange = ((CPTXYPlotSpace*)space).yRange;
    }
    return newRange;}
2
votes

The easiest way to do that is to set the globalYRange of the plot space to the same range as the yRange. If you need to expand the yRange later, remember to remove the globalYRange first (set it to nil).

To get more control, you can use a plot space delegate. Implement this method:

-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
     willChangePlotRangeTo:(CPTPlotRange *)newRange
             forCoordinate:(CPTCoordinate)coordinate;

You can use this method to modify the proposed change to the plot range.