JFreeCharthtml
建立圖表前先設置數據源
數據源:
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
//在數據源中爲每一個字段添加信息,從左到右一次是數據、圖例、軸向名稱
//addValue中三個參數(數據,圖例,軸向名稱)
dataSet.addValue(100, "App", "Apple");
dataSet.addValue(200, "Goo", "Google");
dataSet.addValue(70, "MS", "Microsoft");java
在輸出圖片以前先設置中文編碼
StandardChartTheme theme = new StandardChartTheme("mytheme");
//設置標題字體
theme.setExtraLargeFont(new Font("黑體",Font.BOLD,32));
//設置圖例字體
theme.setRegularFont(new Font("黑體",Font.BOLD,14));
//設置軸向字體
theme.setLargeFont(new Font("黑體",Font.BOLD,14));
ChartFactory.setChartTheme(theme); 工具
生成圖表:
JFreeChart chart = ChartFactory.createBarChart(
"手機佔有率圖", //標題
"公司名稱", //目錄軸名稱
"銷量", //數據周名稱
dataSet, //數據源
PlotOrientation.VERTICAL, //圖標方向:水平,垂直
true, //是否顯示圖例
false, //是否生成工具
false //是否生成URL鏈接
);
FileOutputStream fos = new FileOutputStream(C:\\barchart.jpg");
ChartUtilities.writeChartAsJPEG(fos, chart, 400, 300);
fos.flush();
fos.close();字體
3D柱狀圖
JFreeChart chart = ChartFactory.createBarChart3D(...)編碼
3D餅狀圖
數據源
DefaultPieDataset dataSet = new DefaultPieDataset();
dataSet.setValue("Java", 300);
dataSet.setValue("PHP", 240);
dataSet.setValue(".NET", 140);
• 生成圖表
JFreeChart pieChart = ChartFactory.createPieChart3D("技術統計",
dataSet, true,false,false);
FileOutputStream fos = new FileOutputStream("C:\\piechart.jpg");
ChartUtilities.writeChartAsJPEG(fos, pieChart, 400, 300);
fos.close(); htm
折線圖
數據源
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
dataSet.setValue(130, "A", "1月");
dataSet.setValue(230, "A", "2月");
dataSet.setValue(430, "A", "3月");
dataSet.setValue(330, "A", "4月");
dataSet.setValue(230, "A", "5月");
dataSet.setValue(630, "A", "6月");
dataSet.setValue(140, "B", "1月");
dataSet.setValue(250, "B", "2月");
dataSet.setValue(330, "B", "3月");
dataSet.setValue(560, "B", "4月");
dataSet.setValue(210, "B", "5月");
dataSet.setValue(990, "B", "6月"); 圖片
生成圖表
JFreeChart chart = ChartFactory.createLineChart(「銷售統計」, 「月份」,
"銷量", dataSet, PlotOrientation.VERTICAL, true, false, false);
FileOutputStream fos = new FileOutputStream("C:\\linechart.jpg");
ChartUtilities.writeChartAsJPEG(fos, chart, 400, 300);
fos.close(); ip
更多圖表
http://www.ibm.com/developerworks/cn/java/l-jfreechart/
http://www.jfree.org/jfreechart/samples.html
FlashChart
http://teethgrinder.co.uk/open-flash-chart/
http://www.fusioncharts.com/
JavaScriptChart
http://www.flotcharts.org/
http://www.highcharts.com/flash