Split a axis label on different lines in a barchart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
SimOOn
Posts: 10
Joined: Wed Aug 27, 2008 9:44 am
Contact:

Split a axis label on different lines in a barchart

Post by SimOOn » Wed Nov 12, 2008 4:40 pm

Hi,

in a barchart I have an axis label very long (~50c.) which is taking too much space.

As I have to keep an horizontal orientation, I would like to know if it is possible to split it on different lines ?

I tried to modify it by inserting carriage returns but apparently JFreeChart is ignoring them.

Has anyone a solution for this problem ?

Thanks.

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Wed Nov 12, 2008 5:27 pm

Search the forum for "newline" and you get a load of posts asking the same or related questions (like this one).

For what I can tell it's not possible at the moment.

hth,
- martin

SimOOn
Posts: 10
Joined: Wed Aug 27, 2008 9:44 am
Contact:

Post by SimOOn » Wed Nov 12, 2008 7:06 pm

Before posting, I've first searched the forum for an answer but the only things I've found was related to tick and category labels, not to the axis label.

I've also seached in the documentation and I've found nothing to solve my problem.

To illustrate my problem :
Image

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Thu Nov 13, 2008 8:04 am

Drawing axis labels or tick labels should be the same as both use Graphics2D.drawString(), which obviously doesn't draw line breaks.

Don't know if this is an alternative for you, but you could try to rotate the label by using axis.setLabelAngle().

hth,
- martin

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Nov 13, 2008 9:03 am

Yes, unfortunately the existing code won't support multi-line axis labels. Changing it wouldn't be so hard...you'd need to change two methods in the Axis class:

getLabelEnclosure() - this returns the dimensions of the label, and is used for layout purposes;

drawLabel() - does the actual label drawing.

There is some code in JFreeChart/JCommon that can help with drawing multiline text - see the TextBlock class in JCommon.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

SimOOn
Posts: 10
Joined: Wed Aug 27, 2008 9:44 am
Contact:

Post by SimOOn » Thu Nov 13, 2008 3:52 pm

Ok thanks, I will try to modify these methods to solve my problem.

Locked