Une
Une

Reputation: 41

Jfreechart XYPlot, how can i draw a legend into the Plot-Area?

i'm drawing several charts with XY-Plots in my application. I have no problem displaying a legend under (or on top, left or right of) the plot.

But to save space i want to draw a legend-box into the XY-Plot.

I'm able to draw image-,text- and line-annotations into 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 plot, but nothing is drawn.

If i let the Chart-Object draw the legend under the plot this is done fine (but not what i need).

    chart.addLegend(legend);

So i think the LegendTitle object is correct. But why is it not drawn as Annotation?

I hope someone can figure this out or help me with a different way to draw a legend into the plotarea.

Upvotes: 4

Views: 2646

Answers (2)

Catalina Island
Catalina Island

Reputation: 7126

If you want it to be inside an XYPlot, I think you need an XYTextAnnotation.

Upvotes: 1

Related Questions