I\'ve added a JFreeChart
to a JPanel
(using a BorderLayout
), and it\'s huge. Is there something I can do to make it smaller?<
I had a problem with my pie chart being too big with BorderLayout too. I ended up solving my problem by converting the chart to an image instead.
Before
After
Code
private PieDataset updateCSFDataSet(){
DefaultPieDataset dataSet = new DefaultPieDataset();
dataSet.setValue("Clear(" + clearCount + ")" , clearCount);
dataSet.setValue("Smoky(" + smokyCount + ")", smokyCount);
dataSet.setValue("Foggy(" + foggyCount + ")", foggyCount);
dataSet.setValue("Skipped(" + skipCount + ")", skipCount);
dataSet.setValue("Unlabeled(" + unlabeledCount + ")", unlabeledCount);
return dataSet;
}
private ImageIcon createChart(String title, PieDataset dataSet){
JFreeChart chart = ChartFactory.createPieChart(
title,
dataSet,
true,
false,
false
);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(true);
plot.setIgnoreZeroValues(true);
plot.setLabelGap(0.02);
return new ImageIcon(chart.createBufferedImage(400,300));
}