2.至於JFreeChart的下載配置,在這我就不說了,我給你們傳一份可用代碼源文件,就什麼都解決了。 java
3.下面以餅圖爲例。 字體
public class WritePie_001 { private DefaultPieDataset dataset; public void createPie2DTest() { this.setDefaultStandardChartTheme(); dataset=this.returnPieDataset(); JFreeChart chart=ChartFactory.createPieChart( "龍門集團", //標題 dataset,//數據 true, false, false); try { FileOutputStream fos_jpg = new FileOutputStream("D:\\longmen.jpg"); ChartUtilities.writeChartAsJPEG(fos_jpg, chart, 500, 400); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void createPie3DTest() { this.setDefaultStandardChartTheme(); dataset=this.returnPieDataset(); JFreeChart chart=ChartFactory.createPieChart3D( "龍門集團", dataset, true, false, false); try { FileOutputStream fos_jpg = new FileOutputStream("D:\\longmen3.jpg"); ChartUtilities.writeChartAsJPEG(fos_jpg, chart, 500, 400); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public DefaultPieDataset returnPieDataset() { DefaultPieDataset dp=new DefaultPieDataset(); dp.insertValue(0, "小智", 55); dp.insertValue(1, "河馬", 19); dp.insertValue(2, "金蘋果", 23); dp.insertValue(3, "玄天劍", 15); dp.insertValue(4, "小龍女", 35); return dp; } public void setDefaultStandardChartTheme() { //建立主題樣式 StandardChartTheme standardChartTheme=new StandardChartTheme("CN"); //設置標題字體 Font f=new Font("宋書",Font.PLAIN,20); //設置標題字體 standardChartTheme.setExtraLargeFont(f); standardChartTheme.setSmallFont(f); standardChartTheme.setLargeFont(new Font("宋書",Font.PLAIN,15)); //設置圖例的字體 standardChartTheme.setRegularFont(new Font("宋書",Font.PLAIN,15)); //設置軸向的字體 standardChartTheme.setLargeFont(new Font("宋書",Font.PLAIN,15)); //應用主題樣式 ChartFactory.setChartTheme(standardChartTheme); } }
源文件:jfreechar_0001.rar
this