Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort the legend in JFreeChart?

Is there a way to sort the items in a JFreeChart legend by their backing object?

I've noticed that the TimeSeries/Series sets the title via a Comparable object.

Is there a way or a setting that forces the legend to be sorted by the comparable objects that the items are representing? Currently the legend is sorted by FIFO order.

like image 942
monksy Avatar asked Dec 27 '25 22:12

monksy


1 Answers

You could use the add() method of LegendItemCollection to add the items in the desired order. Most Plots have a setFixedLegendItems() method to override the default.

like image 179
trashgod Avatar answered Dec 30 '25 15:12

trashgod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!