Size calculation of SymbolAxis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Size calculation of SymbolAxis

Post by tdk » Thu Sep 01, 2005 4:31 pm

how does JFree calculate the size of its plot area?

i have the problem, that i need to use a SymbolAxis for the domain axis in order to display some strings rather then numbers. however, i also need the plot to size itself so that every string, ie tick mark, is displayed. how can i force the plot/axis to size itself to achieve that?

thomas

ps: i'm putting the chart in a JScrollPane ...

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

Re: Size calculation of SymbolAxis

Post by david.gilbert » Fri Sep 02, 2005 11:46 am

tdk wrote:how does JFree calculate the size of its plot area?
It's the area left after everything else is placed within the space (rectangle) allocated externally. So it is not possible to get the axis to drive the size of the plot area (and thus the overall chart).
David Gilbert
JFreeChart Project Leader

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

Guest

Post by Guest » Fri Sep 02, 2005 1:03 pm

ok, wrong question.
i'kk try again: what drives the size of the plot area? how can i ensure that all my tick labels can be shown?

thomas

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 Sep 02, 2005 1:31 pm

The plot area is really determined by the chart size (which is specified externally, say by the user resizing a chart panel or saving to an image file with a fixed size image like 600 x 400), less the area required for the titles, legend, and axes. Whatever is left is used as the plot area.

This means the axis has to draw itself at a size matching the plot area, and this can result in overlapping labels. Some axes handle this (NumberAxis and DateAxis automatically adjust the tick size so that labels don't overlap) while others don't (SymbolAxis and CategoryAxis).

It would be nice if JFreeChart could determine the "best" size for a chart, so that all the labels were visible, but it doesn't work that way. Instead, JFreeChart tries to do the "best" job it can to draw a chart at the dimensions it is given.
David Gilbert
JFreeChart Project Leader

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

tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Post by tdk » Mon Sep 05, 2005 10:13 am

> The plot area is really determined by the chart size
i figured that much after several other attempts.

now i calculate the required size of my chartpanel myself (number of tick labels * 20, i have the labels drawn vertically).:

Code: Select all

Dimension size = getPreferredSize();
if (size.width < (xLabels.length * 20)) {
  size.width = xLabels.length * 20;
  setPreferredSize(size);
}
super.setData(data, s, e);
 
the result however is a highly distorted image: still only every nth label is drawn but with a 'zoom effect' in the x-axis, as well as the legend and the title.

puzzled,

thomas

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 » Mon Sep 05, 2005 10:54 am

You need to use the setMaximumDrawWidth() method in the ChartPanel class. This sets the maximum size at which the chart will be drawn - if the panel is larger than that, the chart is scaled up (or stretched) to fit the panel. This (and the maximumDrawHeight attribute) is designed to put an upper limit on the size of the off screen buffered image used by the ChartPanel. If you increase these values, just be aware that the ChartPanel will consume more memory. You can turn off the offscreen buffer, but then moving and resizing the panel won't be as smooth.
David Gilbert
JFreeChart Project Leader

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

tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Post by tdk » Mon Sep 05, 2005 11:30 am

"setMaximumDrawWidth()" does the trick.

thanx,

thomas

Locked