Alignment of legend text

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
schlikkes
Posts: 4
Joined: Mon Sep 17, 2007 3:22 pm
Contact:

Alignment of legend text

Post by schlikkes » Mon Sep 17, 2007 3:29 pm

My legend keys contain line break characters ('\n'). Also the keys are shown as legend text containing multiple lines, all lines are aligned centered.

E.g.:
____short...line 1____
__longer ... line ... 2__
even ... longer .. line 3

I used the '_' in the example above just as fill characters.

I would like to have the legend as following:

short line 1
longer ... line .. 2
even ... longer .. line 3

Does anybody has an idea how to make it?

lucas luky
Posts: 14
Joined: Wed Sep 12, 2007 7:05 pm

Post by lucas luky » Mon Sep 17, 2007 6:53 pm

same problem. no solution yet. :(

schlikkes
Posts: 4
Joined: Mon Sep 17, 2007 3:22 pm
Contact:

Post by schlikkes » Tue Sep 25, 2007 10:12 am

I made a workaround. Not nice but works.

I use a monospace font (e.g. Courier New) for the legend text and make every line of the key as long as the longest line of the key. Therefore I divide the key into several parts for every single line and fill every line with spaces. At the end I paste the parts together with '\n' - character between the lines. The new String is the key of the data.

Tzaphkiel
Posts: 44
Joined: Tue May 13, 2003 1:37 pm
Location: Belgium

Post by Tzaphkiel » Tue Oct 09, 2007 10:11 am

Hi all,

I found out that:

1) if you actually replace \n (which is interpreted as two char by the default setter) by the one char '\n', you'll actually get a line break in the legend items and text block in general.
e.g. I'm loading the text from an XML and it contains something like:

Code: Select all

Line & # 1 0 ; Jump !
where & # 1 0 ; is used with no spaces

2) the alignment to the left and not centered seems to be a problem with the LabelBlock class not calling the

Code: Select all

this.label.setLineAlignment(this.textAlignment);
in the constructor, setFont and setPaint methods...

By overriding it, one can (If I remember correctly from some old code) align the legend items accordingly.
Tzaphkiel
Image

Tzaphkiel
Posts: 44
Joined: Tue May 13, 2003 1:37 pm
Location: Belgium

Post by Tzaphkiel » Tue Oct 09, 2007 10:19 am

Tzaphkiel
Image

Locked