Search code examples
iosobjective-ccore-plot

CPTAxis delegate methods not getting called


// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.5;
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.6] colorWithAlphaComponent:0.75];

CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.labelingPolicy              = CPTAxisLabelingPolicyAutomatic;
x.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
x.majorGridLineStyle          = majorGridLineStyle;
x.minorGridLineStyle          = minorGridLineStyle;
x.preferredNumberOfMajorTicks = 4;
x.minorTicksPerInterval       = 1;

// pin axis to bottom
x.axisConstraints             = [CPTConstraints constraintWithLowerOffset:0.0];

// Y axis
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy              = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
y.majorGridLineStyle          = majorGridLineStyle;
y.minorGridLineStyle          = minorGridLineStyle;
y.preferredNumberOfMajorTicks = 5;
y.minorTicksPerInterval       = 1;
y.delegate = self;

// Pin axis to left
y.axisConstraints             = [CPTConstraints constraintWithLowerOffset:0.0];

I am trying to use -(BOOL)axis:(CPTAxis *)axis shouldUpdateAxisLabelsAtLocations:(NSSet *)locations but is not getting called as suggested in How to set custom tick marks in Core Plot to icons?.


Solution

  • Make sure the delegate class conforms to the <CPTAxisDelegate> protocol and the method has the correct signature:

    -(BOOL)axis:(nonnull CPTAxis *)axis shouldUpdateAxisLabelsAtLocations:(nonnull CPTNumberSet *)locations;