How do I change a JFreeChart's size

前端 未结 4 1902
后悔当初
后悔当初 2020-11-22 09:06

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?<

4条回答
  •  有刺的猬
    2020-11-22 09:35

    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));
        }
    

提交回复
热议问题