how to show one legend item per row in legend area?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
reshin
Posts: 4
Joined: Fri May 23, 2008 10:47 am

how to show one legend item per row in legend area?

Post by reshin » Wed May 28, 2008 1:19 pm

how to show one legend item per row in legend area?
for example:

—— legend text1
—— legend text2
—— llegend text3
—— llegend text4

jpmaia
Posts: 53
Joined: Fri Feb 22, 2008 10:44 pm

Post by jpmaia » Wed May 28, 2008 8:41 pm

Use the following code to change the positioning of the legend from the bottom to the right side (or you could do the LEFT side).

This has the effect of ordering the legend items in a vertical rather than a horizontal alignment. To my knowledge, you can't leave the legend on the bottom AND align them vertically.

Code: Select all

        LegendTitle legend = (LegendTitle) chart.getSubtitle( 0 ); 
        legend.setPosition( RectangleEdge.RIGHT );

reshin
Posts: 4
Joined: Fri May 23, 2008 10:47 am

Post by reshin » Thu May 29, 2008 3:29 am

thank you very much! jpmaia
because the legend text is long, it is not suitable to the right side (or the LEFT side). It will look nice and clear if can leave the legend on the bottom AND align them vertically.

jpmaia
Posts: 53
Joined: Fri Feb 22, 2008 10:44 pm

Post by jpmaia » Thu May 29, 2008 9:08 pm

Actually, I was faced with the same problem as you, but I also had to deal with the possibility of up to 20 series.

I resolved it by doing two things:

1. I decided to keep the legend short, and moved it to the right side.

2. I put the chart in a tabbed pane, then in a second tab, I provided a table listing more detailed info about each series in the legend/chart. For my application, I also provided some editable info in the table that auto-updated in the chart.

reshin
Posts: 4
Joined: Fri May 23, 2008 10:47 am

Post by reshin » Fri May 30, 2008 8:08 am

the legend item show as follow:
—— legend text1 max: maxvalue avg: avgvalue cur: curvalue
—— legend text2 max: maxvalue avg: avgvalue cur: curvalue

so, not to keep the legend short. my project is web project,it is urgent to make me temporarily to give up the effect of ordering the legend items in a vertical rather than a horizontal alignment.

thank you very much for your help again.

jpmaia
Posts: 53
Joined: Fri Feb 22, 2008 10:44 pm

Post by jpmaia » Fri May 30, 2008 8:48 pm

If you need to keep the legend on the bottom, then one way to accomplish your goal is to make each legend item long enough so that only one item fits on a single line.

The legends are ordered left-to-right, as many as fit on a line before wrapping to the next line. If you add even more length to your legend items, then you could force them one on a line.

I believe the items would be left-justified on each line rather than centered however.

reshin
Posts: 4
Joined: Fri May 23, 2008 10:47 am

Post by reshin » Sat May 31, 2008 3:48 am

Hi,jpmaia
you are right, I used the method that make each legend item long enough with whitespace,and accomplished my goal. it is better method before find other method. if you will find other method in the future, please tell me!
thank you very much at all times.

Locked