基于画布 甘特图插件 jQuery simpleGantt.js

  • 源码大小:10.04KB
  • 所需积分:1积分
  • 源码编号:19JP-3265
  • 浏览次数:829次
  • 最后更新:2023年05月24日
  • 所属栏目:图表
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个轻量级的开源jQuery插件,可以帮助开发人员在页面上生成简单的、可定制的、基于HTML5画布的甘特图。它依赖于day.js或moment.js进行日期解析。

该插件提供了项目时间表的清晰可视化表示,可以帮助您识别潜在问题,并根据需要调整项目进度。甘特图上的条形图表示每个任务的持续时间,可用于显示每个任务的开始日期和结束日期。

参见:

  • JavaScript中的10个最佳甘特图插件
  • Javascript和CSS中的10个最佳条形图(柱形图)插件

如何使用它:

1.在文档中加载所需的jQuery和Day.js库。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/cdn/dayjs.min.js"> </script>

2.下载并加载jQuery simpleGantt.js。

  1. <script src="./simpleGantt.js"></script>

3.创建一个HTML5帆布用于甘特图。

  1. <canvas id="myGantt"></canvas>

4.将任务添加到甘特图中,并定义每个任务的开始日期和结束日期,如下所示:

  1. var data = {
  2. "Start": "2016-07-01T00:00:00",
  3. "End": "2019-07-01T00:00:00",
  4. "TotalDays": 1095.0,
  5. "DateProgress": 82,
  6. "Years": [2016, 2017, 2018, 2019],
  7. "Months": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  8. "ScheduleType": "interface",
  9. "Id": 13488,
  10. "Tasks": [
  11. {
  12. "Name": "Project schedule",
  13. "Start": "2016-07-01T00:00:00",
  14. "End": "2019-07-01T00:00:00",
  15. "Description": "From contract award and through the planned execution time",
  16. "Progress": 0,
  17. "TaskType": "project",
  18. "Id": 6,
  19. "DateProgress": 82
  20. },
  21. {
  22. "Name": "Interface",
  23. "Start": "2018-12-12T00:00:00Z",
  24. "End": "2019-01-12T00:00:00Z",
  25. "Description": "Interface, from created date to the due date",
  26. "Progress": 0,
  27. "TaskType": "interface",
  28. "Id": 13488,
  29. "DateProgress": 6
  30. },
  31. {
  32. "Name": "V12005-TRE-PTP",
  33. "Start": "2018-03-19T00:00:00",
  34. "End": "2018-05-07T00:00:00",
  35. "Description": "Trestakk, Piggability Test Procedure, Pig Supply, Propipe",
  36. "Progress": 0,
  37. "TaskType": "document",
  38. "Id": 5250,
  39. "DateProgress": 100
  40. }]
  41. };

5.初始化甘特图插件。

  1. $('#myGantt').simpleGantt({
  2. data: data,
  3. });

6.通过覆盖如下所示的默认选项来自定义甘特图。

  1. $('#myGantt').simpleGantt({
  2. lineColor: 'black',
  3. lineWidth: 1,
  4. margin: 5,
  5. scale: true,
  6. taskHeight: 60,
  7. taskSpacing: 10,
  8. taskContentHeight: 20,
  9. headingHeight: 50,
  10. drawTaskBoxes: true,
  11. drawYearLines: true,
  12. drawMonthLines: true,
  13. monthLineColor: '#c9c9c9',
  14. showMonthNames: true,
  15. showDescriptions: true,
  16. legends: true,
  17. taskColorGradients: true,
  18. showNowLine: true,
  19. showCounters: true,
  20. legendVerticalSpacing: 3,
  21. nowLineColor: 'red',
  22. nowLineWidth: 2,
  23. maxMonths: 30,
  24. taskTitle: {
  25. font: "15px Arial",
  26. color: 'black'
  27. },
  28. taskDescription: {
  29. font: "11px Arial",
  30. color: 'black'
  31. },
  32. heading: {
  33. height: 60,
  34. start: 250,
  35. font: "12px Arial"
  36. },
  37. defaultColor: '#e0e0e0'
  38. });

预览截图