代码如下
View Code
1 import java.awt.Font; 2 import java.io.File; 3 import java.io.IOException; 4 5 import org.jfree.chart.ChartFactory; 6 import org.jfree.chart.ChartFrame; 7 import org.jfree.chart.ChartUtilities; 8 import org.jfree.chart.JFreeChart; 9 import org.jfree.chart.StandardChartTheme; 10 import org.jfree.chart.plot.PiePlot; 11 import org.jfree.chart.plot.PiePlot3D; 12 import org.jfree.chart.plot.PlotOrientation; 13 import org.jfree.chart.title.TextTitle; 14 import org.jfree.data.category.DefaultCategoryDataset; 15 import org.jfree.data.general.DefaultPieDataset; 16 17 18 public class Pie { 19 20 /** 21 * @param args 22 */ 23 public static void main(String[] args) { 24 // TODO Auto-generated method stub 25 DefaultPieDataset dataset=new DefaultPieDataset(); 26 dataset.setValue(" market", new Double(10)); 27 dataset.setValue(" 立项", new Double(15)); 28 dataset.setValue(" 计划", new Double(10)); 29 dataset.setValue(" 需求与设计", new Double(10)); 30 dataset.setValue(" 执行控制", new Double(35)); 31 dataset.setValue(" 收尾", new Double(10)); 32 dataset.setValue(" 运维",new Double(10)); 33 //创建主题样式 34 StandardChartTheme standardChartTheme=new StandardChartTheme("CN"); 35 //设置标题字体 36 standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20)); 37 //设置图例的字体 38 standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15)); 39 //设置轴向的字体 40 standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15)); 41 //应用主题样式 42 ChartFactory.setChartTheme(standardChartTheme); 43 JFreeChart chart=ChartFactory.createPieChart("chinest", dataset, true, false, false); 44 45 try { 46 ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 500, 500); 47 } catch (IOException e) { 48 // TODO Auto-generated catch block 49 e.printStackTrace(); 50 } 51 ChartFrame ChartFrame = new ChartFrame("水果产量图",chart); 52 ChartFrame.pack(); 53 //ChartFrame.setFont(new Font("宋体",Font.BOLD,20)); 54 ChartFrame.setVisible(true); 55 System.out.println("绘图完成"); 56 57 } 58 59 }