質問

I'd like to line up the major grid lines with a background image in my view so I've done this so far:

CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
CPTAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided;
//Other x axis config
NSMutableSet *xMajorLocations = [NSMutableSet set];
[xMajorLocations addObject:[NSNumber numberWithFloat:0.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:341.0f]]; 
[xMajorLocations addObject:[NSNumber numberWithFloat:638.0f]];
x.majorTickLocations = xMajorLocations;

The problem is the major locations are relative to the data plotted. Is there a way to use the view coordinates instead? AND I'd like to keep them stationary when I zoom as with CPTAxisLabelingPolicyEqualDivisions

役に立ちましたか?

解決

Tick locations (and by extension, the grid line locations) are always given in data coordinates. If you want the tick marks, grid lines, and labels to stay in the same place on screen when the plot range changes, you'll need to monitor changes with a plot space delegate. Update the tick locations as needed in the delegate and the labels will be updated automatically to match the new locations.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top