Hello everyone,
A problem I encountered with charts, when there are alot of subtitles, the size of the graph's drawing area (Actual) is not calculated well enough, and subtitles get cut off.
An example:
==============================================
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class Main2 extends ApplicationFrame
{
public Main2(String title)
{
super(title);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "A", "B");
CategoryPlot plot = new CategoryPlot();
BarRenderer rend = new BarRenderer();
rend.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
rend.setItemLabelsVisible(Boolean.TRUE);
plot.setDataset(0, dataset);
plot.setRangeAxis(0, new NumberAxis());
plot.setDomainAxis(0, new CategoryAxis());
plot.setRenderer(0, rend);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
JFreeChart chart = new JFreeChart("Hello Graph", plot);
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
chart.addSubtitle(new TextTitle("Im a subtitle"));
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(640, 480));
setContentPane(chartPanel);
}
public static void main(String[] args)
{
Main2 demo = new Main2("Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
==============================================
Does anyone have any idea how to stop this from happening?
Thanks,
Morwen.
Cut labels and subtitles
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
When I run the posted code, I get this:

I don't see any problem with the subtitles. The item label above the bar is cut off, but this is a different problem (the current workaround for that is to increase the upper margin on the range axis to leave more room for the item labels).

I don't see any problem with the subtitles. The item label above the bar is cut off, but this is a different problem (the current workaround for that is to increase the upper margin on the range axis to leave more room for the item labels).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


My fault sorry - posted the answer to the wrong thread.
My problem is, that the legend area gets to big if I have a lot of series added to my XYSeries. I wanted to know if it's possible to limit the amount of series which are displayed in the legend or define the size of the legend, i.e. give it a fixed height.
Is there a solution to this problem?
regards Stephan
My problem is, that the legend area gets to big if I have a lot of series added to my XYSeries. I wanted to know if it's possible to limit the amount of series which are displayed in the legend or define the size of the legend, i.e. give it a fixed height.
Is there a solution to this problem?
regards Stephan
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The legend just keeps growing to accommodate all the items. Workarounds include:
- hiding the legend;
- using the setSeriesVisibleInLegend() method in the renderer to hide some series from the legend;
- using the setFixedLegendItems() method to display a customised subset of the series;
- subclassing the plot and overriding the getLegendItems() method to return a subset of the series.
- hiding the legend;
- using the setSeriesVisibleInLegend() method in the renderer to hide some series from the legend;
- using the setFixedLegendItems() method to display a customised subset of the series;
- subclassing the plot and overriding the getLegendItems() method to return a subset of the series.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

