Writting Vertical Legends

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Tony

Writting Vertical Legends

Post by Tony » Thu May 02, 2002 5:15 pm

Hi, I'd like to know if it's possible to write the categories in the vertical instead of horizontal...

thanks any help...

David Gilbert

Re: Writing Vertical Legends

Post by David Gilbert » Fri May 03, 2002 10:25 am

Hi Tony,

Try out the setAnchor(...) method in the Legend class. You should be able to use the constants Legend.NORTH, Legend.SOUTH, Legend.EAST and Legend.WEST. East and West will draw the legend "vertically".

Regards,

DG.

Mike Schwartz

Re: Writing Vertical Legends

Post by Mike Schwartz » Thu Nov 20, 2003 7:07 pm

Hi --

I'd like to have a vertical legend with the anchor set to Legend.SOUTH. Is this possible?

Basically, I've got some pie and bar charts which I need to have a vertical legend for, but the lengths of the legend labels can vary, and really don't want their lengths to affect the size of the pie and bar chart, which they do if you anchor them east or west.

Thanks for the great tool-
Mike

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Nov 20, 2003 11:22 pm

It is not possible without rewriting the legend class (which will happen at some point).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Mike Schwartz

Post by Mike Schwartz » Fri Nov 21, 2003 12:49 am

Thanks --

I was able to workaround it by creating 2 plots.. one with just the legend and aligning it underneath using HTML.

The way I created the legend-only plot was rather crude. I extended StandandLegend and overrode the draw() method as follows. Is there a better way to do this?

Code: Select all

public class ChartlessStandardLegend extends StandardLegend {
    public ChartlessStandardLegend(JFreeChart chart) {
        super(chart);
    }
    protected Rectangle2D draw(Graphics2D g2, Rectangle2D available,
                               boolean horizontal, boolean inverted,
                               ChartRenderingInfo info) {
        super.draw(g2, available, horizontal, inverted, info);
        return new Rectangle(0,0);
    }
}

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Nov 21, 2003 10:24 am

That's not a bad workaround. Off the top of my head, it might be possible to make this cleaner by adding a 'legendVisible' flag to the StandardLegend class (or your own extension) so that it functions within the original chart (to fetch legend items etc) but doesn't get drawn. Then you could get your own code to call the draw(...) method (somehow overriding the 'visible' flag) to draw the legend somewhere outside the original chart.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

tiemann45
Posts: 1
Joined: Mon Oct 07, 2019 8:40 pm
antibot: No, of course not.

Re: Writting Vertical Legends

Post by tiemann45 » Mon Oct 07, 2019 9:11 pm

I want to achieve the same behavior. I am using 1.0.19. LegendTitle class doesn't have setAnchor(...) method. Any suggestion?
Thanks,
AW

Locked