我正在尝试使用谷歌折线图。我可以使用x
在页面上打印y
和echo
值,但不在图表中。它给了我以下错误:
" X值列不能是字符串"
我也在DataTable之后关闭了while循环,但它也没有工作。
代码如下:
<?php
@mysql_connect("localhost","root","") or die ("MYSQL'e Baglanti Yok");
@mysql_select_db("exceltosql") or die ("Veritabanina baglanti yapilamadi");
$sql1= "SELECT x,y FROM veri ";
$result1=mysql_query($sql1) or die(mysql_error());
$result_array = array();
while($row1 = mysql_fetch_array($result1)){
$result_array[] = $row1;
echo "<pre>";
echo $row1 ['x'];
echo $row1 ['y'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['x', 'y'],
['<?php $row1 ['x'];?>', '<?php $row1 ['y'];?>'],
]);
var options = {
title: 'VO2 vs. VCO2 grafiği',
hAxis: {title: 'VCO2', minValue: 600, maxValue: 1500},
vAxis: {title: 'VO2', minValue: 600, maxValue: 1500},
legend: 'none'
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
答案 0 :(得分:0)
这一行的结果:
['<?php $row1 ['x'];?>', '<?php $row1 ['y'];?>'],
将是这样的:
['1', '2'],
将数值编码为字符串(如错误消息所示)。删除额外的引号应该可以解决问题:
[<?php $row1 ['x'];?>, <?php $row1 ['y'];?>],