I am making a timechart from previously unknown data. Sometimes there are 2 series, sometimes there are 20. Is it somehow possible to get the legend height? I got 0.0 anytime. I want to keep the same chart dimensions, independent form the legend height. it should be like that:
chart_height = DEFINED_CHART_HEIGHT + LEGEND_HEIGHT
but how to determine legend height?
ChartUtilities.saveChartAsPNG(..., chart, chart_width, chart_height).
Can anyone help?
ps. I am using jFreeChart 1.0rc
determining legend height
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
It is generally not very easy to do this, because JFreeChart was designed to draw everything within the space allocated to it. You might be able to hack something using the arrange() method in the LegendTitle class (which returns the legend size, for given constraints). Once you know the legend size, you could increase the height of the chart by that amount. In theory that should work...I don't know what problems you'll run into in practice.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Thank you very much for quick reply.
No problems encountered. gives exact height of the legend, so I managed to solve my problem.
Best Regards,
alfonso
Code: Select all
Size2D size = chart.getLegend().arrange((Graphics2D) bfi.getGraphics(),
new RectangleConstraint(chartDimX, chartDimY));
Code: Select all
size.height
Best Regards,
alfonso
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Great! I'm glad it worked.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: determining legend height
Hey alfonso I am also interested by your code
What's bfi in : (Graphics2D) bfi.getGraphics() ?
How did you cast/convert your JFreeChart img to a graphics2d ?
What's bfi in : (Graphics2D) bfi.getGraphics() ?
How did you cast/convert your JFreeChart img to a graphics2d ?