`
shz2008bj
  • 浏览: 483040 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用JFreeChart生成饼图实例(生成图片)

阅读更多
package com.lhhc.jfreechart.test;

import java.awt.Font;
import java.io.FileOutputStream;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;

public class PieChartDemo {

    /**
     * @param args
     */
    public static void main(String[] args) throws IOException{
        DefaultPieDataset data=getDataSet();
        JFreeChart chart=ChartFactory.createPieChart3D(
                "图书销量统计图", data, true,
                false, false       
        );
       
        chart.setTitle(new TextTitle("图书销量统计图",new Font("黑体",Font.ITALIC,22)));//标题字体
        //设置图例部分
        LegendTitle legend =chart.getLegend(0);
        legend.setItemFont(new Font("宋体",Font.BOLD,20));//设置图例的字体
        //设置图的部分
        PiePlot plot =(PiePlot)chart.getPlot();
        plot.setLabelFont(new Font("宋体",Font.BOLD,18));//设置实际统计图的字体
        plot.setBackgroundAlpha(0.9f);
        plot.setForegroundAlpha(0.50f);
       
        FileOutputStream fos=new FileOutputStream("book.jpg");
        ChartUtilities.writeChartAsJPEG(
                fos,
                1,
                chart,
                800,
                600,
                null
        );
        fos.close();

    }
    private static DefaultPieDataset getDataSet(){
        DefaultPieDataset dataset=new DefaultPieDataset();
        dataset.setValue("Spring2.0", 47000);
        dataset.setValue("轻量级", 38000);
        dataset.setValue("J2EE的Ajax宝典", 31000);
        dataset.setValue("Ajax in Action", 25000);
        return dataset;
    }

}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics