我正在使用dhtmlxGantt从数据库中生成甘特图。我已经完成了教程,并且在线图表显示正常。当我从数据库中提取数据时,html页面超时并且不显示任何内容。
如果我加载data.php文件,它会立即显示数据库中的数据。我发现,如果我尝试显示内联数据和数据库数据,那么内联加载,然后大约8秒后,db表中的数据加载?此外,数据库数据中的链接也不会显示。有人可以帮忙吗?
来自myGantt.html的代码:
<!DOCTYPE html>
<html>
<style type="text/css" media="screen">
html, body{
margin:10px;
padding:0px;
height:100%;
overflow:hidden;
}
</style>
<head>
<title>How to Start with dhtmlxGantt</title>
<script src="codebase/dhtmlxgantt.js"></script>
<link href="codebase/dhtmlxgantt.css" rel="stylesheet">
</head>
<body>
<div id="gantt_here" style='width:1000px; height:400px;'></div>
<script type="text/javascript">
var tasks = {
data:[
{id:1, text:"Test Project 1",start_date:"01-04-2013", duration:35,
progress: 0.1, open: true},
{id:2, text:"Wire Framing", start_date:"03-04-2013", duration:5,
progress: 0, open: true, parent:1},
{id:3, text:"Design", start_date:"10-04-2013", duration:20,
progress: 0.0, open: true, parent:1},
{id:4, text:"Database Design", start_date:"10-04-2013", duration:5,
progress: 0, open: true, parent:1},
{id:5, text:"System Set up", start_date:"11-04-2013", duration:2,
progress: 0.0, open: true, parent:1},
{id:6, text:"System Presentation", start_date:"24-04-2013", duration:1,
progress: 0.0, open: true, parent:1},
{id:7, text:"Testing", start_date:"25-04-2013", duration:5,
progress: 0.0, open: true, parent:1},
{id:8, text:"Bug Fixing", start_date:"30-04-2013", duration:5,
progress: 0.0, open: true, parent:1},
{id:9, text:"Beta Launch", start_date:"05-05-2013", duration:1,
progress: 0.0, open: true, parent:1}
],
links:[
{id:1, source:1, target:2, type:"1"},
{id:2, source:1, target:3, type:"1"},
{id:3, source:1, target:4, type:"1"},
{id:4, source:1, target:5, type:"1"},
{id:5, source:1, target:6, type:"1"},
{id:6, source:1, target:7, type:"1"},
{id:7, source:1, target:8, type:"1"},
{id:8, source:1, target:9, type:"1"}
]
};
// gantt.config.xml_date = "%Y-%m-%d %H:%i";
gantt.init("gantt_here");
gantt.parse(tasks);
gantt.load("data.php");
// var dp=new dataProcessor("data.php");
// dp.init(gantt);
</script>
</body>
</html>
data.php文件是:
<?php
define('DB_USER','projects_test');
define('DB_PASS','user_pass');
define('DB_HOST','localhost');
include ('codebase/connector/gantt_connector.php');
// include ("./config.php");
$res=mysql_connect(DB_HOST,DB_USER,DB_PASS) or die ("Unable to connect!");
mysql_select_db("projects_test");
$gantt = new JSONGanttConnector($res);
$gantt->render_links("gantt_links","id","source,target,type");
$gantt->render_table(
"gantt_tasks",
"id",
"start_date,duration,text,progress,sortorder,parent"
);
?>
php文件的链接是: http://dev.subzerostudio.com/dhtmlxGantt/data.php
输出可以在以下位置看到:
答案 0 :(得分:2)
这条线帮了我
gantt.config.xml_date = "%Y-%m-%d %H:%i";
http://www.codeproject.com/Articles/1000940/Creating-your-own-online-Gantt-application-with-dh
我的完整代码:
gantt.config.xml_date = "%Y-%m-%d %H:%i";
gantt.init("gantt_here", new Date(2010,7,1), new Date(2010,8,1));
// refers to the 'data' action that we will create in the next substep
gantt.load("./data");
// refers to the 'data' action as well
var dp = new gantt.dataProcessor("./data");
dp.init(gantt);
答案 1 :(得分:0)
您的问题是因为需要加载大量数据。加载数据时肯定会出现问题。用课程来看你的div&#34; gantt_task_row&#34;和gannt_task_row_odd&#34;有近39000个节点...... 在教程中,给出参数&#34; json&#34;解析,也许它是你问题的根源
答案 2 :(得分:0)
如果其他人有同样的问题,我已经找到并解决了这两个问题。我无法从数据库中获取数据的原因就是我将所有条目的父节点设置为1 - 将第一个更改为0解决了问题。
8秒的延迟是从内联元素中提取数据的事实,数据库和日期格式不同。因此,甘特试图显示超过100年的数据.......
现在都在工作。