How to embed the legend inside the CategoryPlot?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
farleylai
Posts: 1
Joined: Fri Mar 27, 2015 7:27 pm
antibot: No, of course not.

How to embed the legend inside the CategoryPlot?

Post by farleylai » Fri Mar 27, 2015 7:42 pm

Hi, all,

This is not a new question as I searched online but it seems like no definitive solution yet.
Only XYTitleAnnotation for XYPlot seems to work but I'm working on CategoryPlot.

It is useful because positioning legends outside the plot area is not desirable due to limited space for publications.
To position legends inside the plot area automatically without losing clarity requires some calculations.
My information may not be up-to-date though.
Is it already supported and can be done with simple settings?
If some custom code overriding is necessary, please give me a hint to do so.

Thanks.
Farley

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: How to embed the legend inside the CategoryPlot?

Post by paradoxoff » Sun Mar 29, 2015 9:14 pm

Placing a legend inside a CategoryPlot is not supported at present.
You can write your own CategoryAnnotation that
a) draws a Title or Legend in its draw method and
b) can be placed anywhere on the plot area.
The source code of XYTitleAnnotation should help you get started. One thing that definitely needs to be changned is the way how the anchor point of the title is calculated. The XYTitleAnnotation is using coordinates that are relative to the range of the x and y axes. I would suggest to use the width and height of the data area instead.

Locked