label background color in line chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
logimine
Posts: 2
Joined: Wed Jan 26, 2005 2:33 pm
Location: Nîmes, France
Contact:

label background color in line chart

Post by logimine » Wed Jan 26, 2005 3:25 pm

Is it possible to set label background color into in line chart ?
Bruno

gandhi
Posts: 11
Joined: Wed Nov 17, 2004 5:24 pm

Post by gandhi » Wed Jan 26, 2005 9:04 pm

No, you can't do it. Quote from the developer's guide:
In the current release of JFreeChart, labels are drawn with a transparent background. You cannot set a background color for the labels, nor can you specify that a border be drawn around the labels. This may change in the future.
If you definitely need it, you should have a look at the drawItemLabel method for the renderer class you are using to render your line chart.
I am not a Java 2D expert, but AFAIK there is nothing like a background color for strings drawn on the Graphic2D device. Which is probably the reason why this possibility does not exist in the JFreeChart API (yet).

You would probably need to add code for drawing filled rectangles before drawing the text of the label. There are methods for determining the space (width) occupied by a text in order to calculate the required width of the rectangle.

Locked