gpt4 book ai didi

javascript - JSGantt 甘特图 - 如何使用日期变量而不是文本

转载 作者:行者123 更新时间:2023-11-28 08:16:14 26 4
gpt4 key购买 nike

我对 Javascript 比较陌生,并且一直在我的网站上使用 JSGantt.js 制作甘特图。 html 页面上所需的唯一代码如下所示:

<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
<script>
// here's all the html code neccessary to display the chart object
// Future idea would be to allow XML file name to be passed in and chart tasks built from file.

var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'quarter');

g.setShowRes(0); // Show/Hide Responsible (0/1)
g.setShowDur(0); // Show/Hide Duration (0/1)
g.setShowComp(0); // Show/Hide % Complete(0/1)
g.setCaptionType('None'); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
g.setShowStartDate(0); // Show/Hide Start Date(0/1)
g.setShowEndDate(0); // Show/Hide End Date(0/1)

//var gr = new Graphics();

if( g ) {
// Parameters (pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption)
// You can also use the XML file parser JSGantt.parseXML('project.xml',g)

g.AddTaskItem(new JSGantt.TaskItem(1, 'Title', '', '', '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));

g.Draw();
g.DrawDependencies();
}
else {
alert("not defined");
}
</script>

在 g.AddTaskItem 函数中,它需要在页面中输入一个日期。我想在它的位置使用现有的日期变量。

我怎样才能做到这一点?感谢您的帮助!如果您想查看提取此信息的 .js 文件,请参见:

JS Gantt Download

最佳答案

假设它需要一个漂亮的 ISO 标准日期字符串,你可以这样做:

function getDate (days) {
if (typeof days === "undefined") {
var days = 0;
}
var date = new Date();
return new Date(date.valueOf() + days*86400000).toISOString().substring(0,10);
}
<snip>
g.AddTaskItem(new JSGantt.TaskItem(1, 'Title', getDate(-30), getDate(), '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));
<snip>

getDate([可选数字]) 将返回今天的日期,并根据您给出的天数进行调整 - 或者如果没有给出参数,则返回今天。理论上你可以在那里执行任何功能。如果这不是正确的日期格式,您可以使用 toDateString() 或其他 date functions 之一来代替 toISOString().substring(0,10) 。如果您愿意,您当然可以调整该函数,甚至在运行时询问用户日期。

关于javascript - JSGantt 甘特图 - 如何使用日期变量而不是文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23566976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com