Multiline axis labels


Hi, I have a bar chart with some very long text labels. However, instead of cropping the text, or wrapping, I get no plot area at all:

I tried inserting carriage return characters in the text for the label (\n), but to no effect.

How to I force a maximum label width, and allow for mutliline labels?

Thanks in advance!



This is possible with the following code:

-(NSString *)sChart:(ShinobiChart *)chart longestLabelStringOnAxis:(SChartAxis *)axis { 
  return @"Longest Line"; 
 - (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis { 
  if ([axis isXAxis]) { 
  tickMark.tickLabel.lineBreakMode = UILineBreakModeClip; 
  tickMark.tickLabel.numberOfLines = 4; 
  tickMark.tickLabel.text = @"First Line\nSecond Line\nThird Line\netc."; 
  [tickMark.tickLabel sizeToFit]; 

Here we are using two delegate methods, the first to fix the width and the second to alter the UILabel. Hope this helps!



Thanks Chris, that worked perfectly!


But how the same will work for dynamic data? when I am getting datapoint like below?

SChartDataPoint *datapoint = [[SChartDataPointalloc] init];

datapoint.xValue = self.xLabel[dataIndex];


Hi Mrbankim,

I’m pretty sure the general method Chris describes here would still work (although you wouldn’t want to hard code the label text). If you start a new forum thread and explain a little bit about your use case, why Chris’ suggestion isn’t working, what you’re seeing, and what you want to see, then we’ll see what we can do to help.  :grin:




We are trying to get a label with 2 lines for each tick-label for the X-axis, but the above code doesn’t work for me. There always is 1 line only.

Also we tried setting the frame of the tickLabel to a big height, but that doesn’t work either. (it is reset again, to the height of 1 line…?)

Can someone help me how to get something like this:

 01     02     03
 Mo    Tu    We



Hi Maarten,

If you post the current code you’re using, we’ll show you how to tweak it to get what you want :slight_smile:


I have a simple idea, Inside the alterTickmarkLabel delegate, create a uilabel, set numberOfLines to 0, set the multiline text and all the sizeToFit method. Add subview the label to tickmark.tickView and set the tickmark.tickLabel to hidden.