Impossible to change order of legend items???

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Impossible to change order of legend items???

Post by rade » Tue Feb 10, 2009 12:02 pm

Now the StandardLegend class that had setRenderingOrder() no longer exists, is it possible at all to change the order of legend items (with LegendRenderingOrder)?

I just lost much time and nerves on this... :)

rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Post by rade » Tue Feb 10, 2009 1:36 pm

Well, it is not possible (for now...)

http://www.jfree.org/phpBB2/viewtopic.php?p=65210#65210

skaczor
Posts: 1
Joined: Fri Mar 09, 2012 8:09 pm
antibot: No, of course not.

Re: Impossible to change order of legend items???

Post by skaczor » Fri Mar 09, 2012 8:13 pm

I had the same issue. Solved it by adding a new method to LegendTitle class. Also made the stacked bars reverse by default, since it is very unintuitive otherwise.

Patch was submitted to the project:
https://sourceforge.net/tracker/?func=d ... tid=315494

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

Re: Impossible to change order of legend items???

Post by matinh » Sun Mar 11, 2012 5:28 pm

Hi Simon!

Thanks for the patch and for updating this thread! That's a patch one can work with! If everybody would provide high quality patches like this, JFreeChart development would move on much faster!

However, I didn't inlucde the part regarding the default behavior change. For reasons see the patch-tracker entry.

kind regards,
- martin

kreska
Posts: 6
Joined: Tue Nov 13, 2018 12:51 pm
antibot: No, of course not.

Re: Impossible to change order of legend items???

Post by kreska » Wed Nov 28, 2018 11:38 am

Hi,

I'm trying to use this method in following way:

Code: Select all

chart.getLegend().setSortOrder( SortOrder.ASCENDING )
but it does not seem to change anything.

Could you please describe what should be done for this to work?

I have XYPlot with DateAxis.

John Matthews
Posts: 464
Joined: Wed Sep 12, 2007 3:18 pm

Re: Impossible to change order of legend items???

Post by John Matthews » Wed Nov 28, 2018 5:59 pm

SortOrder.ASCENDING is the default SortOrder for a LegendTitle. What happens if you specify SortOrder.DESCENDING?

kreska
Posts: 6
Joined: Tue Nov 13, 2018 12:51 pm
antibot: No, of course not.

Re: Impossible to change order of legend items???

Post by kreska » Tue Dec 11, 2018 12:13 pm

The problem is they are not sorted ascending. They are sorted in addition order.

John Matthews
Posts: 464
Joined: Wed Sep 12, 2007 3:18 pm

Re: Impossible to change order of legend items???

Post by John Matthews » Tue Dec 11, 2018 12:57 pm

Right. Addition order is meant to accommodate varying layouts; see fetchLegendItems() for details. For alphanumeric sorting, you might be able to override the method with your own implementation that adds the items in lexicographic order.

kreska
Posts: 6
Joined: Tue Nov 13, 2018 12:51 pm
antibot: No, of course not.

Re: Impossible to change order of legend items???

Post by kreska » Wed Dec 19, 2018 11:25 am

So when this method is used? If it cannot be used like I imagine.

John Matthews
Posts: 464
Joined: Wed Sep 12, 2007 3:18 pm

Re: Impossible to change order of legend items???

Post by John Matthews » Wed Dec 19, 2018 6:55 pm

I've only seen it in LegendTitleTest, but I suppose it might be handy in a vertical legend.

lemming622
Posts: 5
Joined: Wed Dec 05, 2018 8:15 pm
antibot: No, of course not.

Re: Impossible to change order of legend items???

Post by lemming622 » Fri Dec 21, 2018 3:50 pm

If need be you could always use presort your datasets with a tree map or the like before adding your dataset to JFreeChart. That way your have control in java for how the map would sort your datasets. Then to extract the datasets out of the map using any one of a number of map looping mechanisms to then finally add the datasets to your plot.
I'm doing this in a plot set up I have at the moment because I need to scale my axis to an undetermined bound and put bound limits on the plot as well. To keep the legend looking nice I also fill my own LegendItemCollection with the String I want to use for each of the datasets in my plot.

Post Reply