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 ...
Size calculation of SymbolAxis
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Size calculation of SymbolAxis
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).tdk wrote:how does JFree calculate the size of its plot area?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


> 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).:
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
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);
puzzled,
thomas
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

