Impossible to change order of legend items???
Impossible to change order of legend items???
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...
I just lost much time and nerves on this...
Re: Impossible to change order of legend items???
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
Patch was submitted to the project:
https://sourceforge.net/tracker/?func=d ... tid=315494
Re: Impossible to change order of legend items???
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
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
Re: Impossible to change order of legend items???
Hi,
I'm trying to use this method in following way:
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.
I'm trying to use this method in following way:
Code: Select all
chart.getLegend().setSortOrder( SortOrder.ASCENDING )
Could you please describe what should be done for this to work?
I have XYPlot with DateAxis.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Impossible to change order of legend items???
SortOrder.ASCENDING is the default SortOrder for a LegendTitle. What happens if you specify SortOrder.DESCENDING?
Re: Impossible to change order of legend items???
The problem is they are not sorted ascending. They are sorted in addition order.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Impossible to change order of legend items???
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.
Re: Impossible to change order of legend items???
So when this method is used? If it cannot be used like I imagine.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Impossible to change order of legend items???
I've only seen it in LegendTitleTest, but I suppose it might be handy in a vertical legend.
-
- Posts: 5
- Joined: Wed Dec 05, 2018 8:15 pm
- antibot: No, of course not.
Re: Impossible to change order of legend items???
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.
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.