Plot Area x Legend Area

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

Plot Area x Legend Area

Post by Bob Rivers » Thu Dec 12, 2002 7:12 pm

Hi,

I have a "desing" question:

Using the code below, JFreeChart generates the chart correctly, no problem.

How do I control (if is possible) the amount of space destinated to the plot area and legend area ?

My problem is that a have to many itens to be plotted. So, the legend become to big. Sometimes, the legend is bigger than the plot area.

What I want to do, is to fix the plot area, lets say in 40% of the total height amount.

I am saying that, because when these kind of situation occurs, JFreeChart increases the legend and reduces the plot area. It do this because it needs to respect the height (in the case below 450).

Another soluction is to define the width of the chart, but not its height. So, when JFree generates the chart, it will use all the space that it needs.

Is it possible ?

TIA,

Bob - Brazil

--------------------------
JFreeChart chart = ChartFactory.createPieChart("Chart Title", myDefaultPieDataset, true);
PiePlot pp = (PiePlot)chart.getPlot();
pp.setSectionLabelType(3);
pp.setSectionLabelFont(new Font("Arial", Font.PLAIN, 8));
pp.setInteriorGapPercent(0.30);
pp.setCircular(true);
StandardLegend legend = (StandardLegend)chart.getLegend();
legend.setItemFont(new Font("Arial", Font.PLAIN, 8));
TextTitle titulo = (TextTitle)chart.getTitle(0);
titulo.setFont(new Font("Arial", Font.BOLD, 12));
BufferedImage imagePrioridade = chart.createBufferedImage(250, 450);
ImageIO.write(image, "jpeg", new File("grafico.jpeg"))
--------------------------

David Gilbert

Re: Plot Area x Legend Area

Post by David Gilbert » Fri Dec 13, 2002 12:34 am

Hi Bob,

The plot area just gets whatever is left after the chart titles, the legend and the axes have taken what they need. Generally that works out OK, but sometimes it won't. The only suggestion I can offer is to perhaps remove the legend (chart.setLegend(null)) to make more room for the chart...but then you'll need some other way to describe what is on the chart.

Regards,

DG

Locked