由IBM提供 全功能甘特图组件

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

简介

甘特图是一种条形图,可用于在二维时间线界面中可视化数据(活动和计划任务)。

IBM Gantt Chart是一个JavaScript库,它提供了一种简单的方法来实现可定制的、专业的、功能齐全的在线Gantt图表生成器,用于在现代web应用程序上安排任务。

特征:

  • 可与jQuery、Vanilla JavaScript和React.js框架配合使用。
  • 可折叠的任务名称。
  • 反应灵敏,可自动适应您的布局。
  • 自定义日期格式。
  • 自定义时间表渲染和布局。
  • 允许用户放大/缩小甘特图。
  • 允许用户筛选和搜索数据。
  • 支持AJAX数据提取。
  • 支持任何类型的数据:“json”、“xml”、“html”或“text”。

基本用法:

1.加载样式表ibm-gantt-chart.css公司和JavaScriptibm-gantt-chart.js公司来自dist文件夹。

  1. <link href="./dist/ibm-gantt-chart.css" rel="stylesheet" />
  2. <script src="./dist/ibm-gantt-chart.js"></script>

2.为甘特图创建一个占位符。

  1. <div id="gantt"></div>

3.在JS数组中准备数据,该数组包含ID、名称和活动,如下所示。

  1. var data = [
  2. {
  3. id: 'NURSES+Anne',
  4. name: 'Anne',
  5. activities: [
  6. {
  7. id: 'SHIFTS+Emergency+Monday+2+8',
  8. name: 'Emergency',
  9. start: 1474880400000,
  10. end: 1474902000000,
  11. },
  12. ],
  13. },
  14. {
  15. id: 'NURSES+Bethanie',
  16. name: 'Bethanie',
  17. activities: [],
  18. },
  19. {
  20. id: 'NURSES+Betsy',
  21. name: 'Betsy',
  22. activities: [
  23. {
  24. id: 'SHIFTS+Emergency+Wednesday+12+18',
  25. name: 'Emergency',
  26. start: 1475089200000,
  27. end: 1475110800000,
  28. },
  29. {
  30. id: 'SHIFTS+Emergency+Saturday+12+20',
  31. name: 'Emergency',
  32. start: 1475348400000,
  33. end: 1475377200000,
  34. },
  35. {
  36. id: 'SHIFTS+Consultation+Friday+8+12',
  37. name: 'Consultation',
  38. start: 1475247600000,
  39. end: 1475262000000,
  40. },
  41. ],
  42. },
  43. {
  44. id: 'NURSES+Cathy',
  45. name: 'Cathy',
  46. activities: [
  47. {
  48. id: 'SHIFTS+Emergency+Sunday+20+2',
  49. name: 'Emergency',
  50. start: 1475463600000,
  51. end: 1475485200000,
  52. },
  53. {
  54. id: 'SHIFTS+Emergency+Saturday+12+20',
  55. name: 'Emergency',
  56. start: 1475348400000,
  57. end: 1475377200000,
  58. },
  59. {
  60. id: 'SHIFTS+Emergency+Monday+18+2',
  61. name: 'Emergency',
  62. start: 1474938000000,
  63. end: 1474966800000,
  64. },
  65. ],
  66. },
  67. {
  68. id: 'NURSES+Cindy',
  69. name: 'Cindy',
  70. activities: [
  71. {
  72. id: 'SHIFTS+Emergency+Saturday+20+2',
  73. name: 'Emergency',
  74. start: 1475377200000,
  75. end: 1475398800000,
  76. },
  77. {
  78. id: 'SHIFTS+Consultation+Friday+8+12',
  79. name: 'Consultation',
  80. start: 1475247600000,
  81. end: 1475262000000,
  82. },
  83. {
  84. id: 'SHIFTS+Consultation+Tuesday+8+12',
  85. name: 'Consultation',
  86. start: 1474988400000,
  87. end: 1475002800000,
  88. },
  89. ],
  90. },
  91. ];

4.配置如何获取甘特图的资源。

  1. var config = {
  2. data: {
  3. resources: {
  4. data: data, // resources are provided in an array. Instead, we could configure a request to the server.
  5. // Activities of the resources are provided along with the 'activities' property of resource objects.
  6. // Alternatively, they could be listed from the 'data.activities' configuration.
  7. activities: 'activities',
  8. name: 'name', // The name of the resource is provided with the name property of the resource object.
  9. id: 'id', // The id of the resource is provided with the id property of the resource object.
  10. },
  11. // As activities are provided along with the resources, this section only describes how to create
  12. // activity Gantt properties from the activity model objects.
  13. activities: {
  14. start: 'start', // The start of the activity is provided with the start property of the model object
  15. end: 'end', // The end of the activity is provided with the end property of the model object
  16. name: 'name', // The name of the activity is provided with the name property of the model object
  17. },
  18. },
  19. };

5.配置与甘特图关联的工具栏。

  1. var config = {
  2. toolbar: [
  3. 'title',
  4. 'search',
  5. 'separator',
  6. {
  7. type: 'button',
  8. text: 'Refresh',
  9. fontIcon: 'fa fa-refresh fa-lg',
  10. onclick: function(ctx) {
  11. ctx.gantt.draw();
  12. },
  13. },
  14. 'fitToContent',
  15. 'zoomIn',
  16. 'zoomOut',
  17. ],
  18. };

6.初始化库以生成基本甘特图。

  1. new Gantt('gantt', config);

7.将IBM甘特图实现为一个jQuery插件。

  1. <!-- jQuery Library -->
  2. <script src="jquery.min.js"></script>
  3. <!-- jQuery Datatables plugin -->
  4. <script src="jquery.dataTables.min.js"></script>
  5. <link href="jquery.dataTables.min.css" rel="stylesheet" />
  6. <!-- VIS Library -->
  7. <script src="vis.min.js"></script>
  8. <link href="vis.min.css" rel="stylesheet" type="text/css" />
  9. <!-- IBM Gantt Chart -->
  10. <link href="./dist/ibm-gantt-chart-jquery.css" rel="stylesheet" />
  11. <script src="./dist/ibm-gantt-chart-jquery.js"></script>
  1. new Gantt('gantt', config);

8.将IBM甘特图作为React组件来实现。

  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import GanttChart from 'ibm-gantt-chart-react';
  4. import 'ibm-gantt-chart/dist/ibm-gantt-chart.css';
  5. const config = { ... };
  6. ReactDOM.render(<GanttChart config={config} />, document.getElementById('gantt'));

9.将IBM甘特图作为React组件来实现。

  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import GanttChart from 'ibm-gantt-chart-react';
  4. import 'ibm-gantt-chart/dist/ibm-gantt-chart.css';
  5. const config = { ... };
  6. ReactDOM.render(<GanttChart config={config} />, document.getElementById('gantt'));

10.有关高级用法,请访问官方文档了解更多详细信息。

更新日志:

2023-04-14

  • 版本0.5.29

预览截图