|
Wrap Y-axis text |
Posted by Andrew on May-16-2013 22:59 |
|
I've got some long text that is on the Y-axis that I'd like to wrap. Being on the Y, the text is rotated sideways....I've tried using setMaxWidth, but it's not working. I'm not sure if that's because, being sideways, the width is actually the height or if it's something else.
I tried to check that out by seeing what the width and height of the title actually was (using getWidth and getHeight) but they are both returning 0, which may also be my problem.
This also got me wondering about another, sort of separate, question - is there a "new line" character I can pass to control the wrapping myself (that is, if I can't get setMaxWidth do the trick)? I'm using VB, so I tried vbCRLF...that does give a new line, but I see the new line character as a box, so that's not usable. |
Re: Wrap Y-axis text |
Posted by Peter Kwan on May-17-2013 01:06 |
|
Hi Andrew,
In VB, ChartDirector supports vbLF as the newline character.
The vbCrLF are actually two characters (the "carriage return" and the "linefeed"). ChartDirector does not handles the "carriage return" specifically, and so it is displayed just like any other characters. In the Arial font (or many other common fonts), the "carriage return" is not defined in the font, and this results in a square box. Meanwhile, the "linefeed" works as expect and so you still see the new line. Using vbLF would solve the problem, as it only contains the "linefeed" character, not the "carriage return" character.
Also, the setMaxWidth should work even if the text is rotated. Normally, you only need to rotate text on the horizontal axis, and unless you are using XYChart.swapXY, by default, the horizontal axis is the x-axis. So for your case, are you sure you have applied setMaxWidth to the correct axis?
As a test, I have tried:
Set t = c.xAxis().setLabels(labels)
Call t.setFontAngle(90)
Call t.setMaxWidth(20)
The above works normally in my case. The text is wrapped to 20 pixels wide, then the wrapped text is rotated by 90 degrees. (So the wrapping occurs before rotation and so is unaffected by the rotation.)
Regards
Peter Kwan |
Re: Wrap Y-axis text |
Posted by Andrew on May-17-2013 01:21 |
|
Ah - vbLf does the trick...
As for setMaxWidth, I'm definitely using it on the correct axis. Maybe I didn't describe it well, but in a typical XY graph the Y title will pretty much always be vertical...just like it would be in Excel, for example.
I'd rather try to do this with setMaxWidth, but at least I've got a plan B now, if I need it. |
Re: Wrap Y-axis text |
Posted by Andrew on May-17-2013 02:02 |
|
There's got to be something wrong with how I'm getting that axis title textbox object...I just tried setAlignment (because when I use vbLf, it right justifies the text), and it does nothing.
Here's the code (VBA):
Set AxisTitle = c.YAxis.setLabelStyle(, 8)
Call AxisTitle.setAlignment(5)
No erorrs, but it's definitely not doing anything no matter what I put in for an alignment. Also, as I'd mentioned in my first post, I don't get a height or width from getHeight, etc...all of this makes me think that the problem I'm having with setMaxWidth is actually that the textbox object isn't getting returned...am I missing something? |
Re: Wrap Y-axis text |
Posted by Andrew on May-17-2013 02:08 |
|
Here's a screencap so you can see what I mean...
|
Re: Wrap Y-axis text |
Posted by Peter Kwan on May-17-2013 15:45 |
|
Hi Andrew,
Sorry. I misunderstand that you are referring to the labels along the axis (the labels 12, 14, 15, 18, ...). The TextBox object obtained through setLabels or setLabelStyle is for the labels along the axis. For the axis title, the TextBox object is obtained through setTitle. You may use something like:
Set AxisTitle = c.yAxis().setTitle("<*block,halign=center*>" & myTitle, "arialbd.ttf", 18)
Call AxisTitle.setMaxWidth(100)
Hope this can help.
Regards
Peter Kwan |
|