標籤:工具 jquery
JQuery.Gantt是一個開源的基於JQuery庫的用於實現甘特圖效果的可擴充功能的JS組件庫。它既可以圖形化行程安排,也可以展示資料分布。
本人在原有基礎上,修改了部分代碼,較原有功能外,主要改進為:
1、修正“某一條資料為空白時原有的代碼js會報錯的問題”。
2、修正“ie顯示時進度條會閃爍的問題”。
3、json的資料不再為new Date(時間戳記)的形式,直接為時間戳記
為:待定
頁面展示為:
其中,框1為上下翻頁,框2表示滾動到目前時間,框3為捲軸和滾動按鈕,框4為顯示粒度切換。
代碼引入:
<link rel="stylesheet" href="css/style.css" />
<!--包中未包含jquery,你需要自行下載最新版的--><script src="js/jquery-1.7.min.js"></script><script src="js/jquery.fn.gantt.js"></script><!--若為jquery1.9以上,還需要引入--><script src="js/jquery-migrate-1.2.1.min.js"></script>
注意若你引入的jquery為1.9+,則需要引入js/jquery-migrate-1.2.1.min.js,因為jquery1.9+取消了對$.browser的支援,若不引入升級包,則js運行出錯
產生圖表的js代碼如下:
$('選取器').gantt({<span style="white-space:pre"></span>source: source,<span style="white-space:pre"></span>//顯示的資料,見下面分析<span style="white-space:pre"></span>navigate: "scroll",//顯示成scroll還是buttons<span style="white-space:pre"></span>months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],<span style="white-space:pre"></span>//月份顯示的語言<span style="white-space:pre"></span>dow: ["S", "M", "T", "W", "T", "F", "S"],<span style="white-space:pre"></span>//星期顯示的語言<span style="white-space:pre"></span>scale: "weeks",<span style="white-space:pre"></span>//預設顯示的粒度<span style="white-space:pre"></span>maxScale: "months",<span style="white-space:pre"></span>//最大顯示的粒度<span style="white-space:pre"></span>minScale: "days",<span style="white-space:pre"></span>//最小顯示的粒度<span style="white-space:pre"></span>itemsPerPage: 18,<span style="white-space:pre"></span>//每頁顯示的數目<span style="white-space:pre"></span>onItemClick: function(data) {<span style="white-space:pre"></span>//進度條顯示的單擊事件,data參見source定義<span style="white-space:pre"></span>//alert("Item clicked - show some details" + data);<span style="white-space:pre"></span>},<span style="white-space:pre"></span>onAddClick: function(dt, rowId) {<span style="white-space:pre"></span>//圖表空白處的單擊事件<span style="white-space:pre"></span>},<span style="white-space:pre"></span>onRender: function() {<span style="white-space:pre"></span>//渲染時的事件<span style="white-space:pre"></span>}});上面source表示資料來源,其格式如下:
source:[{ name:"Example",//一行的標題 desc:"Something",//某行的描述 values:[{from:"1333411200000",//起始時間,13位時間戳記,這裡不同於原版"/Date(1333411200000)/"to:"1328832000000",//終止時間,13位時間戳記,這裡不同於原版"/Date(1333411200000)/"desc:"Something",//描述label:"Example Value",//顯示在進度條上的標籤customClass:"ganttRed",//顯示的顏色,基本上都是gantt+"顏色名詞"dataObj: dataObj//onclick等事件傳入的資料對象}]}]
其他的參數可參考[1]
參考:
[1] http://www.cnblogs.com/liusuqi/archive/2013/06/09/3129293.html,JQuery.Gantt(甘特圖) 開發指南
JS甘特圖 JQuery.Ganttyy