Search code examples
iosalignmentcore-plot

iOS Core plot - align y axis labels


I want to align the y axis labels of my scatter plot in Core Plot. Currently, the labels are like this:

16

12

8

4

How can I change they alignment to right :

16

12

_8

_4

I tried the following:

y.labelAlignment = CPTAlignmentRight;

It didn't work. How can I do this alignment?

Edit- Here is my code:

CPTAxis *y = axisSet.yAxis;    
y.title = @"Y Label";
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;       
y.axisLineStyle = axisLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;    
y.labelOffset = 16.0f;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 4.0f;
y.minorTickLength = 2.0f;    
y.tickDirection = CPTSignPositive;
y.labelAlignment = CPTAlignmentRight;

Solution

  • You can specify the label direction independently from the tick direction now. To have the tick marks extend to the right of the axis while lining up the labels on the left side, use the following settings:

    y.tickDirection = CPTSignPositive;
    y.tickLabelDirection = CPTSignNegative;
    y.labelOffset = 5.0;