代码如下
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 import org.jfree.data.xy.XYSeries; 17 import org.jfree.data.xy.XYSeriesCollection; 18 19 20 public class xy { 21 22 /** 23 * @param args 24 */ 25 public static void main(String[] args) { 26 // TODO Auto-generated method stub 27 XYSeries xyseries = new XYSeries("First"); 28 xyseries.add(1.0D, 1.0D); 29 xyseries.add(2D, 4D); 30 xyseries.add(3D, 3D); 31 xyseries.add(4D, 5D); 32 xyseries.add(5D, 5D); 33 xyseries.add(6D, 7D); 34 xyseries.add(7D, 7D); 35 xyseries.add(8D, 8D); 36 XYSeries xyseries1 = new XYSeries("Second"); 37 xyseries1.add(1.0D, 5D); 38 xyseries1.add(2D, 7D); 39 xyseries1.add(3D, 6D); 40 xyseries1.add(4D, 8D); 41 xyseries1.add(5D, 4D); 42 xyseries1.add(6D, 4D); 43 xyseries1.add(7D, 2D); 44 xyseries1.add(8D, 1.0D); 45 46 XYSeries xyseries2 = new XYSeries("Third"); 47 xyseries2.add(3D, 4D); 48 xyseries2.add(4D, 3D); 49 xyseries2.add(5D, 2D); 50 xyseries2.add(6D, 3D); 51 xyseries2.add(7D, 6D); 52 xyseries2.add(8D, 3D); 53 xyseries2.add(9D, 4D); 54 xyseries2.add(10D, 3D); 55 56 XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //再用XYSeriesCollection添加入XYSeries 对象 57 xyseriescollection.addSeries(xyseries); 58 xyseriescollection.addSeries(xyseries1); 59 xyseriescollection.addSeries(xyseries2); 60 61 62 63 //创建主题样式 64 StandardChartTheme standardChartTheme=new StandardChartTheme("CN"); 65 //设置标题字体 66 standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20)); 67 //设置图例的字体 68 standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15)); 69 //设置轴向的字体 70 standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15)); 71 //应用主题样式 72 ChartFactory.setChartTheme(standardChartTheme); 73 // JFreeChart chart=ChartFactory.createXYAreaChart("xyPoit", "点的标号", "出现次数", xyseriescollection, PlotOrientation.VERTICAL, true, false, false); 74 JFreeChart chart=ChartFactory.createScatterPlot("xyPoit", "点的标号", "出现次数", xyseriescollection, PlotOrientation.VERTICAL, true, false, false); 75 76 try { 77 ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 500, 500); 78 } catch (IOException e) { 79 // TODO Auto-generated catch block 80 e.printStackTrace(); 81 } 82 // ChartFrame ChartFrame = new ChartFrame("水果产量图",chart); 83 // ChartFrame.pack(); 84 // //ChartFrame.setFont(new Font("宋体",Font.BOLD,20)); 85 // ChartFrame.setVisible(true); 86 // System.out.println("绘图完成"); 87 88 } 89 90 }