Resizing of a chart

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

Resizing of a chart

Post by Oliver Horvath » Tue Mar 20, 2001 5:32 pm

Hi,

I am using JFreeChart 0.5.6 with the horizontal bar chart. I am generrating with the chart some *.gif images.
Now I have a (big) problem:
If I have a gif size of 320 x 240 with 14 bars insite the image is
very well (one category with 14 series).
But I get the values for the chart of a access database. So its
possible to have only one category with four series. In this case
I have VERY BIG bars, because the gif size is the same.
So I have to calculate the size of the picture. For that reason I
need to know, where JFreeChart is calculating the size of the chart,
the size of the bar and ...

My aim to have the same size of all bars (every time with 1 category
and x series, 0 < x < 20) with a different height of the gif
(size of the image with 1 category and 3 series < size of the image with 1 category and 12 series).

What is the proper way to do this?

Regards
O. Horvath

David Gilbert

RE: Resizing of a chart

Post by David Gilbert » Thu Mar 22, 2001 1:40 pm

Hi Oliver,

That's quite difficult to achieve because JFreeChart is designed to draw a chart as best it can within the area you specify - that's why in the demo program you can resize the window and the demo charts adjust in a sensible way (most of the time!)

The size of the bars in a bar chart depends on:

(1) the initial chart size passed to the JFreeChart.draw(...) method - this is controlled by the JFreeChartPanel in the demo program;

(2) the area required to draw the chart title, legend and axes, which depends on the fonts used, the number formats for the tick labels etc.;

(3) the gaps between the bars;

Actually, the size of the bars is about the last thing calculated.

I understand your requirement though - perhaps it would be possible to implement a method recommendSize(...) that works through the components of the chart (title, legend, axes, plot) looking at the dimensions of each and works out the chart size that would give the required bar size. Then you could pass this recommended size to the draw(...) method.

I'll add it to the list of requirements...

Regards,

DG.

Locked