You can create your own source of legend elements. Assuming you have a set of elements matching the legends you want to display, called legendKeys :
class LineLegendItemSource implements LegendItemSource { public LegendItemCollection getLegendItems() { LegendItemCollection itemCollection = new LegendItemCollection(); for (Comparable comparable : legendKeys) { Paint paint =
Then you need to remove the old legends from the diagram and add a new one:
JFreeChart chart = // your chart chart.removeLegend(); LegendTitle legend = new LegendTitle(new LineLegendItemSource()); chart.addLegend(legend);
As you can see, the LegendItem constructor takes shape, so you can basically draw whatever you want.
source share