原創|其它|編輯:郝浩|2012-10-22 10:42:46.000|閱讀 673 次
概述:我最近在做項目的時候,要用到圖表,其中畫圖表工具有好多種,今天我們就對ChartDirector與JreeChart這2種進行學習和比較,掌握技術路徑,即掌握安裝配置方式,接口,調用方法,例子等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
我最近在做項目的時候,要用到圖表,其中畫圖表工具有好多種,今天我們就對ChartDirector與這2種進行學習和比較,掌握技術路徑,即掌握安裝配置方式,接口,調用方法,例子等。
下載了ChartDirector,挺簡單的,照著提供的jsp的例子,改一下數據、橫坐標內容就馬上能運行了,提供的函數命名也很規范,一看大概就知道用途,挺好理解的,生成的圖表也很漂亮。
下載JreeChart,這個東西配置也挺簡單的,圖表質量不如ChartDirector好看,而且生成的圖片的大小還大。
ChartDirector:
JreeChart:
兩款都是流行的Web圖表工具:
ChartDirector:
ChartDirector控件使用方便,快捷,靈活,功能強大,交互性強。在Web服務器以及嵌入式應用程序開發中,它是一種非常理想的工具,擁有豐富的圖表圖形組件庫。支持多種圖表樣式,如圓形圖表(餅狀圖),圓環圖,柱形圖(條形圖),直線圖,曲線圖,梯級線圖,趨勢線圖,曲線擬合圖,線間色圖,區域圖,散布圖(散形圖),泡沫圖等。采用多線程結構,特別應用于具有高性能要求的服務器端應用程序開發。擁有基于API(應用編程接口)的對象,允許用戶控制和定制圖表細節,從而設計出用戶滿意的圖表。
JreeChart:
是一個開源的 JAVA 項目,它主要用來開發各種各樣的圖表,這些圖表包括:餅圖、柱狀圖 ( 普通柱狀圖以及堆棧柱狀圖 ) 、線圖、區域圖、分布圖、混合圖、甘特圖以及一些儀表盤等等。在這些不同式樣的圖表上可以滿足目前商業系統的要求。 JFreeChart 是一種基于 JAVA 語言的圖表開發技術。 JFreeChart 可用于 Servlet 、 JSP 、 Applet 、 Java Appication 環境中,通過 JDBC 可動態顯示任何數據庫數據,結合 Itext 可以輸出至 PDF 文件。
ChartDirector: 商業;價格根據使用權限不同在500元到800元之間;也可以免費使用,只是在畫出來的圖形下面都有一條它的廣告條。網上有破解方法,破解后圖形下面不再出現它的廣告條。
JreeChart: 開源;但是文檔要花錢買,400元;
ChartDirector: 支持很多種語言,例如.NET, Java, ASP, COM,VB, PHP, Perl, Python,Ruby, ColdFusion, C++等;
JreeChart: Java;
ChartDirector: 圖表特別精細,漂亮;
樣例庫:
JreeChart: 畫出來的圖形不夠精細,看起來有些模糊;圖表的文字邊緣、顏色和顏色的分界也比較模糊。
樣例庫:
ChartDirector: 中文的問題,比較容易解決。
JreeChart: 雖然有字體的解決辦法,但仍然存在問題。他使用的默認字體顯示出來的中文會很模糊,你可能需要修改源代碼。
從自己分別使用它們用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>
這個范例說明如何用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>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:軟酷