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,397
  • 3
  • 14
  • 39
monksy
  • 13,936
  • 16
  • 71
  • 122

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
  • 200,320
  • 28
  • 229
  • 974
  • 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