91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何通過JFreeChart實現在jsp頁面畫甘特圖

發布時間:2022-03-31 14:35:04 來源:億速云 閱讀:153 作者:小新 欄目:編程語言

小編給大家分享一下如何通過JFreeChart實現在jsp頁面畫甘特圖,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

首先把重要的代碼粘出來供大家參考,項目源碼和數據庫信息表,以及參考的資料和一些資料的網址我就打包放在下面,大家可以下載后學習參考。

ProgressControl.java//完成從數據庫讀數據,生成甘特圖。

package com.angrybirds.DAO;   import java.io.IOException;  import java.io.PrintWriter;  //import java.util.Date;  import java.sql.*;  import java.util.ArrayList;  import java.util.ListIterator;   import javax.servlet.http.HttpSession;   import org.jfree.chart.ChartFactory;  import org.jfree.chart.ChartRenderingInfo;  import org.jfree.chart.ChartUtilities;  import org.jfree.chart.JFreeChart;  import org.jfree.chart.entity.StandardEntityCollection;  import org.jfree.chart.servlet.ServletUtilities;  import org.jfree.data.gantt.Task;  import org.jfree.data.gantt.TaskSeries;  import org.jfree.data.gantt.TaskSeriesCollection;   public class ProgressControl {            public static String createPlanGanttChart(String missionId,String missionName,HttpSession session,PrintWriter pw){                    String fileName = null;          Connection conn = null;          Statement stmt = null;          ResultSet rs = null;          String sql = null;          String sql2 = null;                    ArrayList nameList = new ArrayList();          ArrayList startList = new ArrayList();          ArrayList endList = new ArrayList();                    conn = DB.getConnection();          stmt = DB.getStatement(conn);                    sql = "select * from SQLJ.Pro_control"; // where Task_id = '" + missionId + "'";                    //System.out.println(sql);                    rs = DB.getResultSet(stmt, sql);                    try {              while(rs.next()){                                    nameList.add(rs.getString("Task_name"));                  startList.add(rs.getDate("Plan_starttime"));                  endList.add(rs.getDate("Plan_endtime"));                                              }          } catch (SQLException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }                    ListIterator iterN = nameList.listIterator();          ListIterator iterS = startList.listIterator();          ListIterator iterE = endList.listIterator();                    TaskSeriesCollection tsc = new TaskSeriesCollection();          TaskSeries tsPlan = new TaskSeries("Plan");                        while(iterN.hasNext()){                            String submissionName = (String)iterN.next();              java.util.Date sDate = (java.util.Date)iterS.next();              java.util.Date eDate = (java.util.Date)iterE.next();                                        if(sDate.before(eDate)){              Task task = new Task(submissionName,sDate,eDate);              tsPlan.add(task);              }              else{}          }              tsc.add(tsPlan);//tsc.add(tsPlan);                                JFreeChart chart = ChartFactory.createGanttChart(missionName + "GanttProject", "Project", "Time", tsc, true, true, true);              ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());                  try {                      fileName = ServletUtilities.saveChartAsPNG(chart, 500, 80+65*nameList.size(), info,session);                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                            try {                      ChartUtilities.writeImageMap(pw, fileName, info,true);                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                            try {                      rs.close();                      stmt.close();                      conn.close();                  } catch (SQLException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                     pw.flush();          //System.out.println(fileName);          return fileName;      }      public static String createRealGanttChart(String missionId,String missionName,HttpSession session,PrintWriter pw){          String fileName = null;          Connection conn = null;          Statement stmt = null;          ResultSet rs = null;          String sql = null;          String sql2 = null;                    ArrayList nameList = new ArrayList();          ArrayList startList = new ArrayList();          ArrayList endList = new ArrayList();                    conn = DB.getConnection();          stmt = DB.getStatement(conn);                    sql = "select * from SQLJ.Pro_control"; // where Task_id = '" + missionId + "'";          //System.out.println(sql);          rs = DB.getResultSet(stmt, sql);          try {              while(rs.next()){                  nameList.add(rs.getString("Task_name"));                                  startList.add(rs.getDate("Reality_starttime"));                  endList.add(rs.getDate("Reality_endtime"));                              }          } catch (SQLException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }          //rs = null;          //System.out.println("over:1");              ListIterator iterN = nameList.listIterator();          ListIterator iterS = startList.listIterator();          ListIterator iterE = endList.listIterator();          TaskSeriesCollection tsc = new TaskSeriesCollection();          //TaskSeries tsPlan = new TaskSeries("Plan");          TaskSeries tsReal = new TaskSeries("Real");          while(iterN.hasNext()){                            String submissionName = (String)iterN.next();              java.util.Date sDate = (java.util.Date)iterS.next();              java.util.Date eDate = (java.util.Date)iterE.next();                                        if(sDate.before(eDate)){                            Task task = new Task(submissionName,sDate,eDate);              tsReal.add(task);              }              else{}                       }              tsc.add(tsReal);//tsc.add(tsPlan);              JFreeChart chart = ChartFactory.createGanttChart(missionName + "GanttProject", "Project", "Time", tsc, true, true, true);              ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());                  try {                      fileName = ServletUtilities.saveChartAsPNG(chart, 500, 80+65*nameList.size(), info,session);                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                  try {                      ChartUtilities.writeImageMap(pw, fileName, info,true);                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                  try {                      rs.close();                      stmt.close();                      conn.close();                  } catch (SQLException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }                     pw.flush();          //System.out.println(fileName);          return fileName;      }  }

我把計劃任務和實際任務分開畫的甘特圖,所以有兩個甘特圖的jsp頁面

PlanGantt.jsp

<%@ page language="java" import="java.util.*,java.io.*" %> <%@ page import="com.angrybirds.DAO.ProgressControl"%> <%  String path = request.getContextPath();  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>AngryBirds</title> <link href="css.css" rel="stylesheet" type="text/css" />     <meta http-equiv="pragma" content="no-cache">     <meta http-equiv="cache-control" content="no-cache">     <meta http-equiv="expires" content="0">          <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">     <meta http-equiv="description" content="This is my page"> </head> <body> <div class="size">   <div class="header">     <div class="header01">       <div class="logo"> <img src="image/img_15.bmp" alt="" /> </div>     </div>     <div class="cmainimg"> <img alt="" src="image/img_73.jpg" /> </div>     <div class="mnav"> <img class="mnimgl" src="image/img_37.jpg" alt="" /> <img class="mnimgr" src="image/img_50.jpg" alt="" />       <div class="mnm">         <ul>                   </ul>       </div>     </div>   </div>   <div class="content">     <div class="submenu" style="left: 0px; top: 0px"> <img class="snimgl" src="image/img_96.jpg" alt="" /> <img class="snimgr" src="image/img_107.jpg" alt="" />       <div class="subtext"> You are here:Home </div>       <div class="subimag" style="width: 41px; height: 51px">         <ul>           <li>1</li>           <li>2</li>           <li>3</li>         </ul>       </div>     </div>     <div class="mcontent">        <!--***************************************************************************&times;&oacute;/-->        <!--***************************************************************************&Oacute;&Ograve;/-->       <div align="center"  class="mcmid3">  <%           String missionId = "1";          String filename = ProgressControl.createPlanGanttChart(missionId,"AllProject",session,new PrintWriter(out));          String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;      %>           <img src="<%=graphURL %>" width="500" height="300" border="0" usemap="#<%=filename %>">       </div>       <!--***************************************************************************/-->     </div>   </div>   <div class="footer"> <img class="mnimgl" src="image/img_275.jpg" alt="" /> <img class="mnimgr" src="image/img_291.jpg" alt="" /> <a href="http://www.88web.org/">HOME</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">ABOUT US</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">GALLERY</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">FAQ</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">SERVICES</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">CONTACT</a> <br/>     <font color="#333333">Copyright 2009 Your Website | <a style="color: #333333" href="http://www.88web.org/css-templates/">CSS Template</a> by <a style="color: #333333" href="http://www.88web.org/">AngryBirds</a></font></div> </div> </body> </html>

RealGantt.jsp

<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="GBK"%> <%@ page import="com.angrybirds.DAO.ProgressControl"%> <%  String path = request.getContextPath();  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  %>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>AngryBirds</title> <link href="css.css" rel="stylesheet" type="text/css" />     <meta http-equiv="pragma" content="no-cache">     <meta http-equiv="cache-control" content="no-cache">     <meta http-equiv="expires" content="0">          <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">     <meta http-equiv="description" content="This is my page"> </head> <body> <div class="size">   <div class="header">     <div class="header01">       <div class="logo"> <img src="image/img_15.bmp" alt="" /> </div>     </div>     <div class="cmainimg"> <img alt="" src="image/img_73.jpg" /> </div>     <div class="mnav"> <img class="mnimgl" src="image/img_37.jpg" alt="" /> <img class="mnimgr" src="image/img_50.jpg" alt="" />       <div class="mnm">         <ul>                     </ul>       </div>     </div>   </div>   <div class="content">     <div class="submenu" style="left: 0px; top: 0px"> <img class="snimgl" src="image/img_96.jpg" alt="" /> <img class="snimgr" src="image/img_107.jpg" alt="" />       <div class="subtext"> You are here:Home </div>       <div class="subimag" style="width: 41px; height: 51px">         <ul>           <li>1</li>           <li>2</li>           <li>3</li>         </ul>       </div>     </div>     <div class="mcontent">        <!--***************************************************************************左/-->             <!--***************************************************************************右/-->       <div align="center" class="mcmid3">     <%           String missionId = "1";          String filename = ProgressControl.createRealGanttChart(missionId,"AllProject",session,new PrintWriter(out));          String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;      %>           <img src="<%=graphURL %>" width="500" height="300" border="0" usemap="#<%=filename %>">       </div>       <!--***************************************************************************/-->     </div>   </div>   <div class="footer"> <img class="mnimgl" src="image/img_275.jpg" alt="" /> <img class="mnimgr" src="image/img_291.jpg" alt="" /> <a href="http://www.88web.org/">HOME</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">ABOUT US</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">GALLERY</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">FAQ</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">SERVICES</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.88web.org/">CONTACT</a> <br/>     <font color="#333333">Copyright 2009 Your Website | <a style="color: #333333" href="http://www.88web.org/css-templates/">CSS Template</a> by <a style="color: #333333" href="http://www.88web.org/">AngryBirds</a></font></div> </div> </body> </html>

此圖為效果圖:(由于我用的是DB2所以時間顯示有點問題,如果要想甘特圖有更好的顯示效果可以參考API文檔中相關類和方法

地址:http://www.jfree.org/jfreechart/api/javadoc/index.html)

如何通過JFreeChart實現在jsp頁面畫甘特圖

看完了這篇文章,相信你對“如何通過JFreeChart實現在jsp頁面畫甘特圖”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

湖州市| 聊城市| 大丰市| 菏泽市| 阿合奇县| 中阳县| 新密市| 介休市| 涿州市| 马尔康县| 定南县| 乌兰察布市| 延长县| 永丰县| 喀什市| 大庆市| 马尔康县| 西城区| 株洲县| 永寿县| 深水埗区| 苍南县| 旺苍县| 永昌县| 长岭县| 砀山县| 金溪县| 吉安县| 右玉县| 左云县| 湟源县| 平罗县| 阳东县| 漳平市| 定州市| 古丈县| 滁州市| 昌都县| 砀山县| 五指山市| 曲阜市|