The fix sized legend for piechart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
chechaquo
Posts: 10
Joined: Tue Oct 28, 2008 12:42 pm

The fix sized legend for piechart

Post by chechaquo » Sun Nov 08, 2009 12:15 pm

Hello,

I have following, perhaps trivial question, but i couldn't find an answer :(

The legend of piechart is positioned on the left. Due to long keys the chart itself becomes small. Is it possible to fix the legend size?

Code: Select all

public class ChartTest {
     public static void main(String[] args) {
        DefaultPieDataset ds = new DefaultPieDataset();
        ds.setValue("very very very long name", 200);
        ds.setValue("just name",90);
        JFreeChart pieChart= ChartFactory.createPieChart("My Chart",  ds,  true, true, false);
        ChartFrame cf = new ChartFrame("Test", pieChart);
        cf.setSize(250, 300);
        LegendTitle title=pieChart.getLegend();
        title.setPosition(RectangleEdge.LEFT);
        pieChart.setBackgroundPaint(Color.white);
        PiePlot piePlot=(PiePlot)pieChart.getPlot();
        piePlot.setLabelGenerator(null);
        cf.setResizable(false);
        cf.setVisible(true);
    }
}
I'm thinking of inserting '\n' in the long keys but i doubt that this is good solution.

Thanks for your help in advance.

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: The fix sized legend for piechart

Post by remiohead » Mon Nov 09, 2009 6:03 pm

Forgive the obvious suggestions: move it to the top/bottom, make font size smaller. My only other suggestion is write a custom layout manager that never makes the legend more that x% of the available width.

chechaquo
Posts: 10
Joined: Tue Oct 28, 2008 12:42 pm

Re: The fix sized legend for piechart

Post by chechaquo » Mon Nov 09, 2009 7:46 pm

remiohead wrote:Forgive the obvious suggestions: move it to the top/bottom, make font size smaller. My only other suggestion is write a custom layout manager that never makes the legend more that x% of the available width.
Thanks for your reply, moving legend and making font size smaller won't work in my case (I have specific design :( )... Writing custom layout manager seems to be very time consuming task :roll: ... so there is no simple solution :(

Locked