使用JFreeChart创建饼图
package com.cs.jfreechart;import java.awt.Color;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 * @throws IOException */public static void main(String[] args) throws IOException {//生成饼图JFreeChart chart = ChartFactory.createPieChart("图书销售统计表", //图表标题getDateSet(), //数据true, //是否显示图例false, //是否显示工具提示false //是否生成URL);//设置标题及标题字体chart.setTitle(new TextTitle("图书销售统计图",new Font("黑体",Font.ITALIC,22)));//建一个图例LegendTitle legendTitle = chart.getLegend(0);//设置图例字体legendTitle.setItemFont(new Font("宋体",Font.BOLD,14));//获取饼图plot对象PiePlot plot = (PiePlot) chart.getPlot();//根据key指定各个数据饼图的颜色plot.setSectionPaint("JAVA教程", Color.RED);plot.setSectionPaint("c++教程", Color.BLUE);plot.setSectionPaint("C#教程", Color.GREEN);plot.setSectionPaint("VC++教程", Color.ORANGE);//设置plot字体plot.setLabelFont(new Font("宋体",Font.BOLD,18));//设置背景透明度(0~1)plot.setBackgroundAlpha(0.9f);//输出文件FileOutputStream fos = new FileOutputStream("book.jpg");//用ChartUtilities工具输出ChartUtilities.writeChartAsJPEG(fos, chart, 800, 600);fos.close();}private static DefaultPieDataset getDateSet() {//提供生成饼图的数据DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("JAVA教程", 47);dataset.setValue("c++教程", 23);dataset.setValue("C#教程", 20);dataset.setValue("VC++教程", 10);return dataset;}}