我被要求做一个自动甘特图。搜索后,我在Google Developer上找到了这个。 Google Gantt Chart
因此,我尝试将Google Gantt Chart与MySQLi结合为数据源。这是我的实际代码:
`<?php
$DB_HOST = 'localhost';
$DB_NAME = 'db_gantt';
$DB_USER = 'root';
$DB_PASS = '';
/* Establish the database connection */
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* select all the weekly tasks from the table */
$result = $mysqli->query('SELECT name,complete FROM task_history');
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Task Name', 'type' => 'string'),
array('label' => 'Percentage', 'type' => 'number')
);
/* Extract the information from $result */
foreach($result as $r) {
$temp = array();
$temp[] = array('v' => (string) $r['name']);
// Values
$temp[] = array('v' => (int) $r['complete']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;
?>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
vardata = new google.visualization.DataTable();
data.addColumn('string', '<?php $jsonTable['name']; ?>');
data.addRows([
['Percentage', '<?php $jsonTable['complete']; ?>',
null, newDate(2015, 0, 6), daysToMilliseconds(1), 100, 'Duration']
]);
var chart = new
google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
</script>
</head>
<body>
<!--this is the div that will hold the chart-->
<div id="chart_div"></div>
</body>
</html>`
但没有任何东西在显示。我从中得到的只是一个白色的空白页面。我正在使用XAMPP
关于如何使这个东西工作的任何想法来运行它?
你们可以帮我解决这个问题吗?谢谢。顺便说一句,我是新手。所以请善待。