public class PieChartDemo {
    public static void main(String[] args) throws IOException{     
        JFreeChart chart=ChartFactory.createPieChart("图书销量统计图", data, true, false, false);       
        chart.setTitle(new TextTitle("图书销量统计图",new Font("黑体",Font.ITALIC,22)));//标题字体   
        //设置图例部分   
        LegendTitle legend =chart.getLegend(0);  
        legend.setItemFont(new Font("宋体",Font.BOLD,18));//设置图例的字体   
        //设置图的部分   
        PiePlot plot =(PiePlot)chart.getPlot();   
        plot.setLabelFont(new Font("宋体",Font.BOLD,15));//设置实际统计图的字体   
        //设置背景透明度
        plot.setBackgroundAlpha(0.1f);   
        //设置饼区的透明度
        plot.setForegroundAlpha(0.90f);             
        FileOutputStream fos=new FileOutputStream("book.jpg");   
        ChartUtilities.writeChartAsJPEG(fos,1,chart,400,400, null);   
        fos.close();     
    }   
    private static DefaultPieDataset getDataSet(){   
        DefaultPieDataset dataset=new DefaultPieDataset();   
        dataset.setValue("Spring2.0", 5000);   
        dataset.setValue("轻量级", 38000);   
        dataset.setValue("J2EE的Ajax宝典", 31000);   
        dataset.setValue("Ajax in Action", 25000);   
        return dataset;   
    }    
}   如上代码,生成图片如下我的问题是:1.让标题不显示;
            2.图示区每块颜色的说明怎么去掉,只保留下面图例部分的说明,因为种类一多的话感觉图会看不清楚
            3.能不能把图例区每个颜色的说明直接挪到图示区右下角,不知道jfreechart支持不

解决方案 »

  1.   


    public static void main(String[] args) throws IOException {
    JFreeChart chart = ChartFactory.createPieChart("图书销量统计图", getDataSet(), true, false, false);
    chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));// 标题字体 //图书销量统计图
    // 设置图例部分
    LegendTitle legend = chart.getLegend(0);
    legend.setPosition(RectangleEdge.RIGHT); //我帮你加的(针对问题3)
    legend.setVerticalAlignment(VerticalAlignment.TOP);  //我帮你加的(针对问题3)
    legend.setItemFont(new Font("宋体", Font.BOLD, 18));// 设置图例的字体
    // 设置图的部分
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(null); ////我帮你加的(设置Label生成为空即可)
    plot.setLabelFont(new Font("宋体", Font.BOLD, 15));// 设置实际统计图的字体
    // 设置背景透明度
    plot.setBackgroundAlpha(0.1f);
    // 设置饼区的透明度
    plot.setForegroundAlpha(0.90f);
    FileOutputStream fos = new FileOutputStream("c:/book.jpg");
    ChartUtilities.writeChartAsJPEG(fos, 1, chart, 600, 300, null); //改了一下你的大小
    fos.close();
    }private static DefaultPieDataset getDataSet() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Spring2.0", 5000);
    dataset.setValue("轻量级", 38000);
    dataset.setValue("J2EE的Ajax宝典", 31000);
    dataset.setValue("Ajax in Action", 25000);
    return dataset;
    }
      

  2.   

    补充:
    不想要标题的话,把chart.setTitle(new TextTitle("图书销量统计图",new Font("黑体",Font.ITALIC,22)));//标题字体改为chart.setTitle(new TextTitle("",new Font("黑体",Font.ITALIC,22)));//标题字体即可!