jfreechart之饼状图
import java.io.FileNotFoundException; 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.data.general.DefaultPieDataset; /** * * @author 刘毅 * @date 2010-2-25 * @ClassName Pie.java * @Email liu_yi126@163.com * @param 饼状图 * @param */ public class Pie { public static void createPie(){ DefaultPieDataset dataset = new DefaultPieDataset(); //第一个参数是数据的名称,第二个数据是数据的值。 dataset.setValue("测试1", 100); dataset.setValue("测试2", 200); dataset.setValue("测试3", 300); dataset.setValue("测试4", 100); JFreeChart chart = ChartFactory.createPieChart("测试,标题", dataset, true, false, false); //炸开的饼图 PiePlot pp = (PiePlot) chart.getPlot(); pp.setExplodePercent("测试1",1); //炸开的饼图需要和上面数据的名字一致 //设置中文字体 JfreeChinese.setChineseForPie(chart); FileOutputStream fos = null; try { fos = new FileOutputStream("src/pie.png"); ChartUtilities.writeChartAsPNG(fos, chart, 400, 300); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if(null != fos){ fos.close(); } } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { Pie.createPie(); } }