JfreeChart學(xué)習(xí)總結(jié)_第1頁(yè)
JfreeChart學(xué)習(xí)總結(jié)_第2頁(yè)
JfreeChart學(xué)習(xí)總結(jié)_第3頁(yè)
JfreeChart學(xué)習(xí)總結(jié)_第4頁(yè)
JfreeChart學(xué)習(xí)總結(jié)_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、JfreeChart學(xué)習(xí)總結(jié) 關(guān)鍵字: jfreechart 自己最近學(xué)習(xí)了JfreeChart的使用,覺(jué)得這個(gè)冬冬的功能非常強(qiáng)大,總結(jié)一下。主要介紹JfreeChart生成圖片的幾種方式 先從網(wǎng)上找點(diǎn)介紹。 一、簡(jiǎn)介     WW 的發(fā)展使得基于因特網(wǎng)的應(yīng)用程序不再局限于靜態(tài)或者簡(jiǎn)單的動(dòng)態(tài)內(nèi)容提供。傳統(tǒng)的一些以軟件包形式發(fā)布應(yīng)用程序例如報(bào)表系統(tǒng)等都在逐漸搬到因特網(wǎng)上。但是這 兩者之間有著天壤之別,雖然對(duì)于數(shù)據(jù)獲取、業(yè)務(wù)處理等方面基本類似,但是最大的差別在于用戶界面。為了能在web瀏覽器上顯示要求用戶界面使用 HTML以及圖片的方式來(lái)展現(xiàn)數(shù)據(jù),而傳統(tǒng)的一些利用操作

2、系統(tǒng)本身的控件來(lái)開(kāi)發(fā)的用戶界面無(wú)法適應(yīng)琳瑯滿目的客戶端,因此在這里也變得無(wú)能為力?;氐奖疚?的題目上來(lái),為了創(chuàng)建一個(gè)可以在web瀏覽器上查看到圖表一般有兩種做法:第一種就是使用applet利用java本身對(duì)圖形的支持來(lái)顯示一個(gè)圖表;第二 種就是直接在web服務(wù)器端生成好圖表圖片文件后發(fā)送給瀏覽器。第一種方式顯然對(duì)于客戶端要求太高,隨著現(xiàn)在主流瀏覽器放棄對(duì)JAVA的支持后,這種方式 只適合一些局域網(wǎng)的應(yīng)用,而對(duì)于因特網(wǎng)的環(huán)境就顯得不太適合。因此我們下面將介紹一個(gè)JAVA的圖表引擎JFreeChart用來(lái)產(chǎn)生基于WEB的圖表。     JFreeChart 項(xiàng)目簡(jiǎn)介

3、JFreeChart是開(kāi)放源代碼站點(diǎn)上的一個(gè)JAVA項(xiàng)目,它主要用來(lái)各種各樣的圖表,這些圖表包括:餅圖、柱狀圖(普 通柱狀圖以及堆棧柱狀圖)、線圖、區(qū)域圖、分布圖、混合圖、甘特圖以及一些儀表盤(pán)等等。這些不同式樣的圖表基本上可以滿足目前的要求。 二、JFreeChart獲取。          JFreeChart 是JFreeChart公司在開(kāi)源網(wǎng)站上的一個(gè)項(xiàng)目,該公司的主要產(chǎn)品有如下:          1.JFreeReport :

4、報(bào)表解決工具          2.JFreeChart:Java 圖形解決方案(Application/Applet/Servlet/Jsp)          3.JCommon :JFreeReport和JFreeChart的公共類庫(kù)          4.JFreeDesigner :JFreeReport的報(bào)表設(shè)計(jì)工具   &#

5、160;  我們可以從jfree官方網(wǎng)站上獲取最新版本和相關(guān)資料(但是jfree的document需要40美金才能獲?。?     獲取地址:(同時(shí)可以獲得簡(jiǎn)明介紹)      我們以當(dāng)前最新版本:jfreechart-1.0.1.zip為例子進(jìn)行說(shuō)明。 三、JFreeChart配置安裝      1 、解壓jfreechart-1.0.1.zip.zip到指定位置,其中source是jfreechart的源碼,jfreechart-1.0.1-demo.jar&

6、#160;  是例子程序,可以先運(yùn)行一下看看各種效果,就知道他的nb之處了。     2 、為了配置成功,我們需要關(guān)注的文件有如下三個(gè):     設(shè)置classpath。加入下面三個(gè)jar包。     jfreechart-1.0.1.jar 、jcommon-1.0.0.jar、gnujaxp.jar     加上第三個(gè)jar包有時(shí)web.xml會(huì)報(bào)錯(cuò),把它去掉就好了。         至此jf

7、reechart的配置就完成了,下面就可以進(jìn)行jfreechart的開(kāi)發(fā)了。這里值得提出的是jfreechart的類         結(jié)構(gòu)設(shè)計(jì)前后兼容性不是很好,不同版本的jfreechart中類庫(kù)結(jié)構(gòu)可能不一樣,有時(shí)候可能需要查源碼。如果是中文顯示的時(shí)候可能依據(jù)觀感需要改變?cè)创a的字體。 四、JFreeChart功能介紹      JFreeChart 目前是最好的java圖形解決方案,基本能夠解決目前的圖形方面的需求,主要包括如下幾個(gè)方面:    

8、60; pie   charts   (2D   and   3D) :餅圖(平面和立體)      bar   charts   (regular   and   stacked,   with   an   optional   3D   effect) :柱狀圖   

9、60;  line   and   area   charts :曲線圖      scatter   plots   and   bubble   charts      time   series,   high/low/open/close   charts   and &

10、#160; candle   stick   charts :時(shí)序圖      combination   charts :復(fù)合圖      Pareto   charts      Gantt   charts :甘特圖      wind   plots,   meter  

11、 charts   and   symbol   charts      wafer   map   charts      ( 態(tài)圖表,餅圖(二維和三維)   ,   柱狀圖   ( 水平,垂直),線圖,點(diǎn)圖,時(shí)間變化圖,甘特圖,   股票行情圖,混和圖,   溫度計(jì)圖,   刻度圖等常用商用圖表

12、)      圖形可以導(dǎo)出成PNG和JPEG格式,同時(shí)還可以與PDF和EXCEL關(guān)聯(lián)      JFreeChart 核心類庫(kù)介紹:              研究jfreechart源碼發(fā)現(xiàn)源碼的主要由兩個(gè)大的包組成:org.jfree.chart,org.jfree.data。其中前者主要與圖形      本身有關(guān),后者與圖形顯示的數(shù)據(jù)有關(guān)。具體研究如果

13、大家有興趣的話可以自己研究    。           核心類主要有:             org.jfree.chart.JFreeChart :圖表對(duì)象,任何類型的圖表的最終表現(xiàn)形式都是在該對(duì)象進(jìn)行一些屬性的定制。JFreeChart引擎本身提供了一個(gè)工廠類用于創(chuàng)建不同類型的圖表對(duì)象       &

14、#160;     tegory.XXXDataSet: 數(shù)據(jù)集對(duì)象,用于提供顯示圖表所用的數(shù)據(jù)。根據(jù)不同類型的圖表對(duì)應(yīng)著很多類型的數(shù)據(jù)集對(duì)象類             org.jfree.chart.plot.XXXPlot :圖表區(qū)域?qū)ο?,基本上這個(gè)對(duì)象決定著什么樣式的圖表,創(chuàng)建該對(duì)象的時(shí)候需要Axis、Renderer以及數(shù)據(jù)集對(duì)象的支持         

15、60;   org.jfree.chart.axis.XXXAxis :用于處理圖表的兩個(gè)軸:縱軸和橫軸             org.jfree.chart.render.XXXRender :負(fù)責(zé)如何顯示一個(gè)圖表對(duì)象             org.jfree.chart.urls.XXXURLGenerator: 用于生成Web圖表中每個(gè)項(xiàng)目的鼠標(biāo)點(diǎn)

16、擊鏈接             XXXXXToolTipGenerator: 用于生成圖象的幫助提示,不同類型圖表對(duì)應(yīng)不同類型的工具提示類     個(gè)人感覺(jué)JFreeChart可以滿足大部分圖片創(chuàng)建的需要,美中不足的是:對(duì)字體的設(shè)置做的不夠好,特別是使用中文的時(shí)候字體很不清晰。因?yàn)檫@個(gè)原因建 議你自己去修改他的源代碼,最好使用properties文件去設(shè)置字體.還有就是文檔要錢(qián)所以要多花點(diǎn)時(shí)間去看源代碼?;蚨嗌仙鐓^(qū). 五開(kāi)始開(kāi)發(fā)   &

17、#160; 對(duì)JfreeChart有了初步了解并做好準(zhǔn)備工作之后,開(kāi)始作例子程序試驗(yàn)。在這里我只介紹餅圖的做法,而這張圖采用不同的方式進(jìn)行輸出,其他類型的圖片可以參考jfreechart提供的例子,做法都差不多。 1) 直接生成圖片 Java代碼 1. public class PieChartPicture   2. public static void main(String args)   3.   4.  PieDataset 

18、dataset = getDataSet();  5.  JFreeChart chart = ChartFactory.createPieChart3D(  6.     " 項(xiàng)目進(jìn)度分布", / chart title  7.     dataset,/ data  8.   

19、0; true,/ include legend  9.     true,  10.     false  11.    );  12.   PiePlot3D  plot=(PiePlot3D)chart.getPlot();  13.     / 圖片中顯示百分比

20、:默認(rèn)方式  14.     /plot.setLabelGenerator(new           StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT);  15. / 圖片中顯示百分比:自定義方式,0 表示選項(xiàng), 1 表示數(shù)值, 2&#

21、160;表示所占比例 ,小數(shù)點(diǎn)后兩位  16.  plot.setLabelGenerator(new StandardPieSectionLabelGenerator("0=1(2)", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%");   17. / 圖例顯示百分比:自定義方式, 0 表示選項(xiàng), 1 表示數(shù)值, 

22、;2 表示所占比例                  18.  plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("0=1(2)");   19. / 設(shè)置背景色為白色   20. chart.setBackgroun

23、dPaint(Color.white);   21. / 指定圖片的透明度(0.0-1.0)   22.  plot.setForegroundAlpha(1.0f);   23. / 指定顯示的餅圖上圓形(false)還橢圓形(true)   24. plot.setCircular(true);   25. / 設(shè)置圖標(biāo)題的字體   26. Font font&#

24、160;= new Font(" 黑體",Font.CENTER_BASELINE,20);   27. TextTitle title = new TextTitle(" 項(xiàng)目狀態(tài)分布");   28. title.setFont(font);    29. chart.setTitle(title);   30.  fos_jpg&#

25、160;= null;   31. try    32.      fos_jpg=new ("D: 項(xiàng)目狀態(tài)分布.jpg");   33.      ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null);   34.   &

26、#160;  fos_jpg.close();   35.  catch (Exception e)    36.     37.    38. private static PieDataset getDataSet()    39. DefaultPieDataset dataset = new 

27、;DefaultPieDataset();   40. dataset.setValue(" 市場(chǎng)前期", new Double(10);   41. dataset.setValue(" 立項(xiàng)", new Double(15);   42. dataset.setValue(" 計(jì)劃", new Double(10);   4

28、3. dataset.setValue(" 需求與設(shè)計(jì)", new Double(10);   44. dataset.setValue(" 執(zhí)行控制", new Double(35);   45. dataset.setValue(" 收尾", new Double(10);   46. dataset.setValue(" 運(yùn)維&qu

29、ot;,new Double(10);   47. return dataset;          48.   49.    public class PieChartPicture public static void main(String args) PieDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.cre

30、atePieChart3D( " 項(xiàng)目進(jìn)度分布", / chart title dataset,/ data true,/ include legend true, false ); PiePlot3D plot=(PiePlot3D)chart.getPlot(); / 圖片中顯示百分比:默認(rèn)方式 /plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT);/ 圖片中顯示百分比:自定義方式,0 表示選項(xiàng), 1

31、 表示數(shù)值, 2 表示所占比例 ,小數(shù)點(diǎn)后兩位 plot.setLabelGenerator(new StandardPieSectionLabelGenerator("0=1(2)", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"); / 圖例顯示百分比:自定義方式, 0 表示選項(xiàng), 1 表示數(shù)值, 2 表示所占比例 plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("0=1(2)&quo

32、t;); / 設(shè)置背景色為白色 chart.setBackgroundPaint(Color.white); / 指定圖片的透明度(0.0-1.0) plot.setForegroundAlpha(1.0f); / 指定顯示的餅圖上圓形(false)還橢圓形(true) plot.setCircular(true); / 設(shè)置圖標(biāo)題的字體 Font font = new Font(" 黑體",Font.CENTER_BASELINE,20); TextTitle title = new TextTitle(" 項(xiàng)目狀態(tài)分布"); title.setFon

33、t(font); chart.setTitle(title); fos_jpg = null; try fos_jpg=new ("D: 項(xiàng)目狀態(tài)分布.jpg"); ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null); fos_jpg.close(); catch (Exception e) private static PieDataset getDataSet() DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setVa

34、lue(" 市場(chǎng)前期", new Double(10); dataset.setValue(" 立項(xiàng)", new Double(15); dataset.setValue(" 計(jì)劃", new Double(10); dataset.setValue(" 需求與設(shè)計(jì)", new Double(10); dataset.setValue(" 執(zhí)行控制", new Double(35); dataset.setValue(" 收尾", new Double(10); datase

35、t.setValue(" 運(yùn)維",new Double(10); return dataset; 2) 采用servlet和struts的action方式輸出 采用這種方式輸出,不用生成圖片。 A servlet輸出 Java代碼 1. public class PieByServlet extends HttpServlet   2. public void service(ServletRequest req, ServletResponse res)

36、   3. throws ServletException, IOException   4.    5.    res.setContentType("image/jpeg");   6.    PieDataset dataset = getDataSet();   7.    JFr

37、eeChart chart = ChartFactory.createPieChart3D(   8.    " 水果餅圖", / chart title   9.    dataset,/ data   10.    true, / include legend  &

38、#160;11.    true,   12.    false );   13.    /設(shè)置圖表屬性  14. / 輸出圖片   15.  ChartUtilities.writeChartAsJPEG(res.getOutputStream(),100,chart,800,600,null);   16.   &

39、#160;public class PieByServlet extends HttpServlet public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException res.setContentType("image/jpeg"); PieDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.createPieChart3D( " 水果餅圖", / c

40、hart title dataset,/ data true, / include legend true, false ); /設(shè)置圖表屬性/ 輸出圖片 ChartUtilities.writeChartAsJPEG(res.getOutputStream(),100,chart,800,600,null); B struts的action方式輸出 只將這條語(yǔ)句加上try catch即可,并返回null。 Java代碼 1. try         2. ChartUtilities.writeChar

41、tAsJPEG(response.getOutputStream(),100,chart,800,600,null);   3.   catch (Exception e)    4.   5. return null;   try ChartUtilities.writeChartAsJPEG(response.getOutputStream(),100,chart,800,600,null); catch (Excepti

42、on e) return null; 其實(shí)采用這兩種方式與生成圖片的方式改動(dòng)并不大 加上語(yǔ)句response.setContentType("image/jpeg"); ChartUtilities.writeChartAsJPEG(new ("D: 項(xiàng)目狀態(tài)分布.jpg");,100,chart,640,480,null); 文件流改成response的輸出流就可以了 hartUtilities.writeChartAsJPEG(response.getOutputStream(),100,chart,800,600,null); 3)jspservl

43、etjavabean方式 1. Create ChartViewer servlet Java代碼 1. public class ChartViewer extends HttpServlet    2. public void init() throws ServletException   3.    4. /Process the HTTP Get request

44、60; 5. public void doGet(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException    6. / get the chart from session  7. HttpSession session =

45、0;request.getSession();   8. BufferedImage chartImage = (BufferedImage) session.getAttribute("chartImage");   9. / set the content type so the browser can see this as a pictur

46、e   10. response.setContentType("image/png");   11. / send the picture   12. PngEncoder encoder = new PngEncoder(chartImage, false, 0, 9);   13. response.getOutputStream().write(en

47、coder.pngEncode();  14.    15. /Process the HTTP Post request   16. public void doPost(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException  &

48、#160; 17. doGet(request, response);   18.    19. /Process the HTTP Put request   20. public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, 

49、;IOException    21.    22. /Clean up resources   23. public void destroy()     24.    public class ChartViewer extends HttpServlet public void init() throws ServletException /Process the HTT

50、P Get requestpublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException / get the chart from sessionHttpSession session = request.getSession(); BufferedImage chartImage = (BufferedImage) session.getAttribute("chartImage"); / set the con

51、tent type so the browser can see this as a picture response.setContentType("image/png"); / send the picture PngEncoder encoder = new PngEncoder(chartImage, false, 0, 9); response.getOutputStream().write(encoder.pngEncode(); /Process the HTTP Post request public void doPost(HttpServletReque

52、st request, HttpServletResponse response) throws ServletException, IOException doGet(request, response); /Process the HTTP Put request public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException /Clean up resources public void destroy() 2. Create

53、a servlet map in web.xml Java代碼 1. <?xml version="1.0" encoding="UTF-8"?>   2. <web-app>   3.  <servlet>   4.  <servlet-name>ChartViewer</servlet-name>   5.  <ser

54、vlet-class>myapp.webwork.servlets.ChartViewer</servlet-class>   6. </servlet>   7. <servlet-mapping>   8. <servlet-name>ChartViewer</servlet-name>   9. <url-pattern>/servlet/ChartViewer</url-pattern

55、>   10. </servlet-mapping>   11. </web-app>   <?xml version="1.0" encoding="UTF-8"?> <web-app> <servlet> <servlet-name>ChartViewer</servlet-name> <servlet-class>myapp.webwork.servlets.

56、ChartViewer</servlet-class> </servlet> <servlet-mapping> <servlet-name>ChartViewer</servlet-name> <url-pattern>/servlet/ChartViewer</url-pattern> </servlet-mapping> </web-app> 3. Create a chart in a java bean (Pie3DDemo.java) Java代碼 1. public

57、0;class Pie3DDemo    2. private DefaultPieDataset getDataset()    3. / categories.   4. String section = new String  "Jan","Feb","Mar","Apr","May"

58、;,"Jun", "Jul","Aug","Sep","Oct","Nov","Dec"    5. / data.   6. double data = new doublesection.length;   7.  for (int i = 0;

59、 i < data.length; i+)    8.      datai = 10 + (Math.random() * 10);   9.    10. / create the dataset.   11. DefaultPieDataset dataset

60、0;= new DefaultPieDataset();   12. for (int i = 0; i < data.length; i+)    13.        dataset.setValue(sectioni, datai);   14.    15. return&#

61、160;dataset;   16.    17. public String getChartViewer(HttpServletRequest request, HttpServletResponse response)    18.  DefaultPieDataset dataset = getDataset();   19. / create th

62、e chart.   20.  JFreeChart chart = ChartFactory.createPie3DChart(   21.   "Pie3D Chart Demo",  / chart title   22.   dataset,       

63、60;     / data   23.   true,                / include legend   24.   true,   25.   false   

64、;26.  );   27. / set the background color for the chart.   28. chart.setBackgroundPaint(Color.cyan);   29. PiePlot plot = (PiePlot) chart.getPlot();   30. plot.setNoDataMessage(&qu

65、ot;No data available");   31. / set drilldown capability.   32.  plot.setURLGenerator(new StandardPieURLGenerator("Bar3DDemo.jsp","section");   33. plot.setLabelGenerator(null);   

66、34. / OPTIONAL CUSTOMISATION COMPLETED.   35. ChartRenderingInfo info = null;   36. HttpSession session = request.getSession();   37. try    38. /Create RenderingInfo object &

67、#160; 39.  response.setContentType("text/html");   40.  info = new ChartRenderingInfo(new StandardEntityCollection();   41.  BufferedImage chartImage = chart.createBufferedImage(640, 400, info);&

68、#160;  42. / putting chart as BufferedImage in session,   43. / thus making it available for the image reading action Action.   44. session.setAttribute("chartImage",

69、0;chartImage);   45. PrintWriter writer = new PrintWriter(response.getWriter();   46. ChartUtilities.writeImageMap(writer, "imageMap", info);   47. writer.flush();   48.  catch (Exception

70、60;e)     49.   50. String pathInfo = "http:/"   51. pathInfo += request.getServerName();   52. int port = request.getServerPort();   53. pathInfo += ":&qu

71、ot;+String.valueOf(port);   54. pathInfo += request.getContextPath();   55. String chartViewer = pathInfo + "/servlet/ChartViewer"   56. return chartViewer;   57.    public cl

72、ass Pie3DDemo private DefaultPieDataset getDataset() / categories. String section = new String "Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec" ; / data. do

73、uble data = new doublesection.length; for (int i = 0; i < data.length; i+) datai = 10 + (Math.random() * 10); / create the dataset. DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < data.length; i+) dataset.setValue(sectioni, datai); return dataset; public String getChar

74、tViewer(HttpServletRequest request, HttpServletResponse response) DefaultPieDataset dataset = getDataset(); / create the chart. JFreeChart chart = ChartFactory.createPie3DChart( "Pie3D Chart Demo", / chart title dataset, / data true, / include legend true, false ); / set the background col

75、or for the chart. chart.setBackgroundPaint(Color.cyan); PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data available"); / set drilldown capability. plot.setURLGenerator(new StandardPieURLGenerator("Bar3DDemo.jsp","section"); plot.setLabelGenerator(

76、null); / OPTIONAL CUSTOMISATION COMPLETED. ChartRenderingInfo info = null; HttpSession session = request.getSession(); try /Create RenderingInfo object response.setContentType("text/html"); info = new ChartRenderingInfo(new StandardEntityCollection(); BufferedImage chartImage = chart.creat

77、eBufferedImage(640, 400, info); / putting chart as BufferedImage in session, / thus making it available for the image reading action Action. session.setAttribute("chartImage", chartImage); PrintWriter writer = new PrintWriter(response.getWriter(); ChartUtilities.writeImageMap(writer, "

78、;imageMap", info); writer.flush(); catch (Exception e) String pathInfo = "http:/" pathInfo += request.getServerName(); int port = request.getServerPort(); pathInfo += ":"+String.valueOf(port); pathInfo += request.getContextPath(); String chartViewer = pathInfo + "/servl

79、et/ChartViewer" return chartViewer; 6. 頁(yè)面 Java代碼 1.    2. <html>   3. <head>   4. <title>Pie Chart Demo</title>   5. </head>   6. <jsp:useBeanid="myChart"scope="s

80、ession"class="myapp.webwork.beans.Pie3DDemo" />   7. <body>   8. <h2>Pie Chart Demo</h2>   9. <%String chartViewer = myChart.getChartViewer(request, response);%>   

81、;10. <img src="<%=chartViewer%>" border=0 usemap="#imageMap">   11. </body>   12. </html>    <html> <head> <title>Pie Chart Demo</title> </head> <jsp:useBeanid=&qu

82、ot;myChart"scope="session"class="myapp.webwork.beans.Pie3DDemo" /> <body> <h2>Pie Chart Demo</h2> <%String chartViewer = myChart.getChartViewer(request, response);%> <img src="<%=chartViewer%>" border=0 usemap="#imageMap&quo

83、t;> </body> </html> 4)采用工具類ChartUtil和DisplayChart(jfreechart的servlet)輸出 我用了上面的幾個(gè)方法輸出圖片,發(fā)現(xiàn)頁(yè)面里只能輸出一個(gè)圖片, 不過(guò)下面的方法可以輸出多個(gè)圖片,而且是幾種方式中最簡(jiǎn)單的一個(gè),推薦使用。 這種方式和上面的三種比較類似,是將javabean里的生成圖片的方法寫(xiě)的一個(gè)工具類ChartUtil里面。 1 添加工具類ChartUtil public class ChartUtil /  產(chǎn)生時(shí)間序列圖,返回圖片名稱 Java代碼 1. public  s

84、tatic String generatePieChart(DefaultPieDataset dataset,String title,int width,int height,HttpSession session, PrintWriter pw)    2.   3. String  = null;   4.  try    5.  if (session !=

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論