我正在尝试通过从mysql数据库传递值来将google的甘特图用于网站。但是我只看到一个空白页。
我想使用的图表是: gantt chart
我当前使用的甘特代码是:
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
$connect = mysqli_connect("localhost", "root", "", "registration");
?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawGanttChart);
function drawGanttChart() {
var data = new google.visualization.arrayToDataTable();
data.addColumn('string', 'taskid');
data.addColumn('string', 'taskname');
data.addColumn('string', 'membername');
data.addColumn('string', 'sdate');
data.addColumn('string', 'edate');
data.addColumn('string', 'duration');
data.addColumn('number', 'percentage');
data.addColumn('string', 'dependency');
data.addRows([
['taskid', 'taskname', 'membername', 'sdate', 'edate','duration', 'percentage', 'dependency'],
<?php
$query10 = "select * from gantt";
$result10 = mysqli_query($connect, $query10);
while($row = mysqli_fetch_array($result10))
{
echo "['".$row["taskid"]."', '".$row["taskname"]."', '".$row["membername"]."', ".$row["sdate"].", ".$row["edate"].", ".$row["duration"].", ".$row["percentage"].", ".$row["dependency"]."],";
}
?>
]);
var options = {
height: 400,
gantt: {
trackHeight: 30
}
};
var chart = new google.visualization.Gantt(document.getElementById('Gantt_chart_div'));
chart.draw(data, options);
}
</script>
<body>
<div id="Gantt_chart_div" style="border: 1px solid #ccc"></div>
</body>
</html>
请注意,我设法使用不同的数据来使pie chart正常工作,但是我无法获得正确的甘特图语法,饼图(有效)代码如下:
function drawSarahChart() {
var data = google.visualization.arrayToDataTable([
['domain', 'NUMBER'],
<?php
//$query="SELECT projects.id, count(*) as NUMBER FROM projects INNER JOIN users ON projects.members = users.email";
$query = "SELECT projects.domain, COUNT(projects.domain) AS NUMBER FROM projects INNER JOIN users ON projects.members = users.email WHERE users.company = 'vit' GROUP BY projects.domain ";
$result5 = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result5))
{
echo "['".$row["domain"]."', ".$row["NUMBER"]."],";
}
?>
]);
var options = {title:'Classification on the basis of domain',
is3D: true,
width:400,
height:400};
var chart = new google.visualization.PieChart(document.getElementById('Sarah_chart_div'));
chart.draw(data, options);
}