Axis date label in two lines


#1

Hi,

I am building a Bar Chart, where the y axis is a SChartDateTimeAxis. I need this y label to be in this format, for example, for each bar:

Wed,
15/04

I’m feeding the datapoint yValye with a NSDate.

Is it possible to format the label so that I can have it like that, in two lines? I’ve already tried the way I would do with a regular label, but it shows only the first line.

Thanks!


#2

Hi,

You should be able to do the following to achieve this:

#pragma mark - SChartDelegate
- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (![axis isXAxis]) { return; }
    tickMark.tickLabel.numberOfLines = 0;
    
    CGRect frame = tickMark.tickLabel.frame;
    frame.size.height = [axis.width integerValue] - [axis.style.majorTickStyle.tickGap integerValue];
    
    tickMark.tickLabel.frame = frame;
}

- (NSString *)sChart:(ShinobiChart *)chart longestLabelStringOnAxis:(SChartAxis *)axis
{
    if (![axis isXAxis]) { return nil; }
    return @"YOUR LONGEST LABEL X STRING GOES HERE";
}

Hope this helps!

Rob


#3

Hi Rob,

It’s actually for the y axis, so the if statements shouldn’t have the “!”. Anyway, I’m still not getting it… The text is being displayed in two lines, but this frame height setting is giving me a label with half the height of one line (so there is only half a line being displayed).

I tried to change this line that sets the height with the following:

frame.size.height = frame.size.height * 2;

This way I get the two-line label showing just fine, but I can’t get it centered with each bar.

Any sugestions?

Thanks!


#4

Eventually I was able to accomplish that by doing the following:

CGRect frame = tickMark.tickLabel.frame;
    frame.size.height = frame.size.height * 2;
    frame.origin.y = tickMark.tickLabel.center.y - frame.size.height/2;