3

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.

Line
  • 1,529
  • 3
  • 18
  • 42
monksy
  • 14,156
  • 17
  • 75
  • 124

1 Answers1

1

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I use default colors in my stack bar chart (not setting them). Can I somehow order the labels automatically, to preserve their correlation with data colors? – Line Nov 28 '18 at 11:07
  • A suitable [`DrawingSupplier`](https://stackoverflow.com/search?q=user%3A230513+%5Bjfreechart%5D+DrawingSupplier) should work; see [ask] if you get stuck. – trashgod Nov 28 '18 at 13:56