Jfreechart XYPlot, how can I draw a legend in the Plot-Area?

I am drawing several XY graphs in my application. I have no problem displaying the legend (either on top, left or right) of the plot.

But to save space, I want to draw a legend field in XY-Plot.

I can draw graphic, text and string annotations in the plot.

So, I tried to make a TitleAnnotation from my LegendTitle and add this annotation to the plot.

LegendTitle legend = new LegendTitle(plot.getRenderer()); XYTitleAnnotation anno = new XYTitleAnnotation(20.0, 40.0, legend); plot.addAnnotation(anno); 

The coordinates of the annotation (20.0, 40.0) are in the visible area of ​​the graph, but nothing is drawn.

If I let Chart-Object draw a legend on the plot, this is done perfectly (but not what I need).

  chart.addLegend(legend); 

So, I think the LegendTitle object is correct. But why is it not drawn as an annotation?

I hope someone can figure it out or help me in another way draw a legend on the site.

+4
source share

All Articles