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