Reverse Axis Label Alignment


#1

We are using a chart with the only Y axis being on the right side of the chart.  Unfortunately the text labels are right aligned and this is not the desired look.  We have tried setting the alignment on the tick label using the following code, but it does not work.

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (axis == chart.yAxis)
    {
         tickMark.tickLabel.textAlignment = NSTextAlignmentLeft;
    }
}

Unfortunately, it appears that the chart is overring this.  Does anyone know of a way to set the label alignment?


#2

I managed to get my labels left aligned by doing the following:

-(void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (axis == chart.yAxis)
    {
        CGRect frame = tickMark.tickLabel.frame;
        frame.size.width = [tickMark.tickLabel.text sizeWithFont:tickMark.tickLabel.font].width;
        tickMark.tickLabel.frame = frame;
    }
}

However, the method you were trying before should be working and you’re right, it seems as though the alignment is being overridden. I’ve raised this as a bug and we will be investigating it.

Thanks!
Jan


#3

Thanks for the help.  This is alot cleaner of a work-around than we had been using.  Looking forward to the fix… woudl be nice if this was exposed by way of the style.


#4

No worries! Happy to help.


#5

Hey Cheers. Work-around seems okay, but just wanted to let you know the root issue still seems to be there.


#6

Btw, if you’re using iOS7, you’ll want to use sizeWithAttributes instead:

- (void)sChart:(ShinobiChart *)theChart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (chart == theChart && axis == chart.yAxis) {
        CGRect frame = tickMark.tickLabel.frame;
        if (tickMark.tickLabel) {
             frame.size.width = [tickMark.tickLabel.textsizeWithAttributes:@{NSFontAttributeName:tickMark.tickLabel.font}].width;
            tickMark.tickLabel.frame = frame;
        }
    }

}