ChartDirector與JFreeChart兩款主要web圖表工具調研報告

來源:互聯網
上載者:User
摘抄:

一、引言:
    實習單位安排讓調研報表工具選擇一款,讓學習和比較ChartDirector與Jasperreports,掌握技術路徑,即掌握安裝配置方式,介面,調用方法,例子等。
    於是,下載了ChartDirector,挺簡單的,照著提供的jsp的例子,改一下資料、橫座標內容就馬上能運行了,提供的函數命名也很規範,一看大概就知道用途,挺好理解的,產生的圖表也很漂亮。
    於是,下載Jasperreports,這個東東要跑起來還真有點麻煩,首先得瞭解一下ANT,ant不難,但是為了運行一下樣本還是被它拉路了一小會,然後是jdk版本相容問題,然後是資料來源的串連問題,折騰了一個星期,總會把它的樣本都跑起來了,同時也寫了三份學習筆記。接著瞭解了一下它的可視化設計工具ireports。總的感覺這個東西不如ChartDirector方便好用。
    接著,跟莫sir討論一下,發現自己犯了一個很嚴重的概念性錯誤。那就是,圖表和報表是不同的!圖表是指圖片,即柱狀圖,折線圖,餅圖等,選擇圖表工具主要關注的是圖表是否漂亮;而報表是指表格形式的表,如財務報表等,選擇報表工具主要關注的是能否解決中國報表表頭複雜,交叉報表等問題。ChartDirector是圖形報表工具;而Jasperreports是報表工具,組建圖表底層用的是JreeChart。所以,應該比較的是ChartDirector與JreeChart,而不是ChartDirector與Jasperreports的比較。
    下面主要介紹和比較ChartDirector與JreeChart這兩款web圖形報表工具。

二、    ChartDirector與JreeChart的介紹與比較
2.1    官方網址
ChartDirector:  http://www.advsofteng.com/
JreeChart:  http://www.jfree.org/jfreechart/index.html
2.2    基本介紹
兩款都是流行的web圖表工具;
ChartDirector:  
ChartDirector is a fast and powerful charting component for creating professional and clickable charts. It's innovative ChartDirector Mark Up Language, flexible object oriented API, layering architecture and advanced coloring system provide unprecedent chart design, formatting and customization capabilities to developers. Supports numerous chart types - Pie, donut, bar, line, spline, step line, trend line, curve-fitting, inter-line coloring, area, scatter, bubble, floating box, box-whisker, waterfall, finance (numerous indicators support), gantt, vector, radar, polar, rose, angular and linear meters and guages. ChartDirector is 100% pure Java code and is suitable for both client and server side usage. Specially designed graphics subsystem allows ChartDirector to run on headless servers without requiring headless support. Includes SWING controls to support client side applications. Easy to use and with comprehensive documentation. Come with numerous examples.

JreeChart: 
JFreeChart是一個開源的 JAVA 項目,它主要用來開發各種各樣的圖表,這些圖表包括:餅圖、柱狀圖 ( 普通柱狀圖以及堆棧柱狀圖 ) 、線圖、地區圖、分布圖、混合圖、甘特圖以及一些儀錶盤等等。在這些不同式樣的圖表上可以滿足目前商業系統的要求。 JFreeChart 是一種基於 JAVA 語言的圖表開發技術。 JFreeChart 可用於 Servlet 、 JSP 、 Applet 、 Java Appication 環境中,通過 JDBC 可動態顯示任何資料庫資料,結合 Itext 可以輸出至 PDF 檔案。

2.3    收費情況
ChartDirector:  商業;價格根據使用許可權不同在59美元到749美元之間;也可以免費使用,只是在畫出來的圖形下面都有一條它的廣告條。網上有破解方法,破解後圖形下面不再出現它的廣告條。

JreeChart:      開源;但是文檔要花錢買,40美元;

2.4    支援語言
ChartDirector:  支援很多種語言,例如.NET, Java, ASP, COM,VB, PHP, Perl, Python,Ruby, ColdFusion, C++等;
JreeChart:      Java;

2.5    圖表比較
ChartDirector:  圖表特別精細,漂亮;
範例庫:http://www.advsofteng.com/gallery.html
 

JreeChart:      畫出來的圖形不夠精細,看起來有些模糊;圖表的文字邊緣、顏色和顏色的分界也比較模糊。
範例庫:http://www.jfree.org/jfreechart/samples.html
 

2.6    對中文問題支援的比較
ChartDirector:  中文的問題,比較容易解決。
JreeChart:      雖然有字型的解決辦法,但仍然存在問題。他使用的預設字型顯示出來的中文會很模糊,你可能需要修改原始碼。

2.7    開發使用易用性比較
從自己分別使用它們用jsp顯示柱狀圖的例子來看,兩者的開發的易用性差不多,都是設定一下資料、橫座標等就可以了。

三、    分別用ChartDirector和JFreeChart畫柱狀圖的JSP程式樣本
3.1 用ChartDirector在JSP中畫統計圖
      下面是一個柱狀圖的例子:
 
      範常式序:
 <%@page import="ChartDirector.*" %>
 <%
 //The data for the bar chart
  double[] data = {85, 156, 179.5, 211, 123};
 
 //The labels for the bar chart
  String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
 
 //Create a XYChart object of size 300 x 280 pixels
 XYChart c = new XYChart(300, 280);
 
 //Set the plotarea at (45, 30) and of size 200 x 200 pixels
 c.setPlotArea(45, 30, 200, 200);
 
 //Add a title to the chart
 c.addTitle("Weekly Server Load");
 
 //Add a title to the y axis
 c.yAxis().setTitle("MBytes");
 
 //Add a title to the x axis
 c.xAxis().setTitle("Work Week 25");
 
 //Add a bar chart layer with green (0x00ff00) bars using the given data
 c.addBarLayer(data, 0xff00).set3D();
 
 //Set the labels on the x axis.
 c.xAxis().setLabels(labels);
 
 //output the chart
 String chart1URL = c.makeSession(request, "chart1");
 
 //include tool tip for the chart
 String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: {value} MBytes'")
     ;
 %>
 <html>
 <body topmargin="5" leftmargin="5" rightmargin="0">
 <div style="font-size:18pt; font-family:verdana; font-weight:bold">
     3D Bar Chart
 </div>
 <hr color="#000080">
 <a href="viewsource.jsp?file=<%=request.getServletPath()%>">
     <font size="2" face="Verdana">View Chart Source Code</font>
 </a>
 </div>
 <br>
 <img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
     usemap="#map1" border="0">
 <map name="map1"><%=imageMap1%></map>
 </body>
 </html>
 

3.2 用JFreeChart畫柱狀圖的範例

這個範例說明如何用JFreeChart畫簡單的柱狀圖,下面是一個JSP的簡單範例:
 <%@ page contentType="text/html; charset=GB2312" %>
 <%@ page import="java.awt.*, java.text.*, java.util.*" %>
 <%@ page import="org.jfree.chart.*" %>
 <%@ page import="org.jfree.chart.axis.*" %>
 <%@ page import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator" %>
 <%@ page import="org.jfree.chart.plot.*" %>
 <%@ page import="org.jfree.chart.renderer.*" %>
 <%@ page import="org.jfree.chart.servlet.ServletUtilities" %>
 <%@ page import="org.jfree.data.DefaultCategoryDataset" %>
 <%@ page import="org.jfree.ui.TextAnchor" %>
 
 <%
   //The data for the bar chart
    double[] data = {85, 156, 179.5, 211, 123};
   //The labels for the bar chart
    String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
   
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < data.length; i++) {
     dataset.addValue(data[i], null, labels[i]);
   }
   
   JFreeChart chart = ChartFactory.createBarChart3D("Weekly Server Load", "Work Week 25", "MBytes", dataset, PlotOrientation.VERTICAL, false, false, false);
   chart.setBackgroundPaint(new Color(0xE1E1E1));
   
   CategoryPlot plot = chart.getCategoryPlot();
   
   // 設定Y軸顯示整數
   NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
   rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   
   CategoryAxis domainAxis = plot.getDomainAxis();
   //設定距離圖片左端距離
   domainAxis.setLowerMargin(0.05);
   
   BarRenderer3D renderer = new BarRenderer3D();
   //設定柱的顏色
   renderer.setSeriesPaint(0, new Color(0xff00));
   plot.setRenderer(renderer);
   
   String filename = ServletUtilities.saveChartAsPNG(chart, 300, 280, null, session);
   String graphURL = request.getContextPath() + "/displayChart?filename=" + filename;
 %>
 <html>
 <body topmargin="5" leftmargin="5" rightmargin="0">
 <div style="font-size:18pt; font-family:verdana; font-weight:bold">
     3D Bar Chart
 </div>
 <br>
 <img src="<%= graphURL %>" border=0>
 </body>
 </html>
 
畫出來的圖:
 
和ChartDirector畫出來的圖做一個比較:
 
四、    web圖表工具選擇
瞭解了關鍵的兩款web圖表工具ChartDirector與JreeChart之後,我們應該選擇哪一個報表工具呢?下面是本人提供的參考方案:
ChartDirector:圖片精細漂亮,如果捨得花錢購買,建議使用這款;
JreeChart:圖片不夠清晰有些模糊,如果只考慮免費工具,建議使用這款;

五、    參考資料
1.    http://www.advsofteng.com/
2.    http://www.jfree.org/jfreechart/index.html
3.    ChartDirector (Java Edition)
http://nuclearscripts.com/java/jsp-and-servlets/graphs-and-charts/chartdirector-java-edition.html
4.    JFreeChat的介紹http://www.blogjava.net/chunkyo/archive/2007/01/13/jfreechat.html
5.    用JFreeChart畫柱狀圖的範例
    用ChartDirector在JSP中畫統計圖
http://www.blogjava.net/georgehill/default.html?page=3
6.    一個很棒的WEB圖表項目??ChartDirector
http://www.dlog.cn/html/diary/showlog.vm?sid=2&cat_id=-1&log_id=413
7.    ChartDirector與JFreeChart
http://blog.csdn.net/keelsike/archive/2006/05/30/762869.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.