可以使用Deneb中的Gantt Chart插件来获得下拉式层次甘特图。代码示例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Drop-down hierarchical Gantt chart in Deneb</title>
<link rel="stylesheet" href="https://cdn.denebtools.com/latest/deneb-gantt-chart.min.css">
</head>
<body>
<div id="gantt"></div>
<script src="https://cdn.denebtools.com/latest/deneb-gantt-chart.min.js"></script>
<script>
var tasks = [
{
id: 1,
name: 'Task 1',
start: '2021-01-01',
end: '2021-01-05',
children: [
{
id: 2,
name: 'Sub-task 1',
start: '2021-01-01',
end: '2021-01-03'
},
{
id: 3,
name: 'Sub-task 2',
start: '2021-01-04',
end: '2021-01-05'
}
]
},
{
id: 4,
name: 'Task 2',
start: '2021-01-06',
end: '2021-01-10'
}
];
var gantt = new Deneb.GanttChart(document.getElementById('gantt'), tasks, {
startDate: '2021-01-01',
endDate: '2021-01-15',
collapsible: true,
hierarchical: true
});
</script>
</body>
</html>
该示例创建了一个具有两个任务和一个子任务的层次Gantt图,并使用了Deneb的Gantt Chart插件来创建它。其中,使用collapsible: true
将任务行设置为可折叠的,并使用hierarchical: true
启用了层次结构。这将会在任务名称旁边添加一个下拉箭头,以展开或折叠子任务。