order of series in the legend.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hongping
Posts: 14
Joined: Thu Jul 29, 2004 1:32 am

order of series in the legend.

Post by hongping » Tue Aug 10, 2004 6:38 pm

Currently when I use the StackedXYAreaChart, the area first series is displayed at the bottom of the chart, and the legend also shows the chart color of the first series on the left most position.

Eg.

Chart:
C
B
A

Legend: A B C

Is there a way to make it such that the legned will start showing series from the top most area to the bottom one?

Chart:
A
B
C

Legend: A B C

hongping
Posts: 14
Joined: Thu Jul 29, 2004 1:32 am

Post by hongping » Wed Aug 11, 2004 6:06 pm

I found out that it can be done using the setRenderingOrder method of the StandardLengend class, which takes in an object of class org.jfree.chart.LegendRenderingOrder and you can use that to specify standard or reverse order of the legend.

opeongo

JFreecharts 1.0.0-rc1

Post by opeongo » Mon Oct 03, 2005 9:29 pm

It looks like the StandardLegend class has been depricated. Is there anyway to reverse the legend order using the new Block classes?

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Mon Oct 03, 2005 9:49 pm

I believe the recommended approach is to change the order in the dataset. When this is done, the legend will reorder the next time the same chart refreshes.

Daniel

Opeongo

Post by Opeongo » Tue Oct 04, 2005 2:19 pm

But wont this cause exactly the same problem in reverse?

I can see that the legend will get reversed, but will this also cause the order of the series in the plot to be reversed as well?

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 » Tue Oct 04, 2005 5:02 pm

You'll need to override the getLegendItems() method in the XYPlot class to change the order of the items. Better still, modify XYPlot to include a flag that determines the order of the returned items, and submit a patch that I can incorporate into the next release.
David Gilbert
JFreeChart Project Leader

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

Opeongo

Post by Opeongo » Tue Oct 04, 2005 7:12 pm

I was thinking of a more generalized change to LegendTitle or BlockContainer. Perhaps if done right it could be implemented in one location, and then applied to each plot type.

However, I am not sure if this would work correctly, because the calculation of the bounding box might be depended on display order. Perhaps serveral methods in BlockContainer and Arrangement would have to change.

As I look at the code it seems like your proposed method would be much simpler, although it would have to be made to each implementation of getLegendItems.

At this stage what do you suggest?
1) modify XYPlot.getLegentItems()
2) modify LegendTitle, BlockContainer, Arrangement

Locked