使用php和sql时,Google Charts不会显示 [英] Google Charts won't display when using php and sql
问题描述
我使用Google图表创建了一个简单的图表。我在执行数据时使用PHP和MYSQL。我正在寻找答案并尝试过,但没有显示图表
这是我的 test.php 文件
< html>
< head>
< script type =text / javascriptsrc =https://www.gstatic.com/charts/loader.js>< / script>
< script type =text / javascript>
google.charts.load('current',{packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
函数drawChart(){
//定义要绘制的图表。
var data = google.visualization.arrayToDataTable([
['Specialization','Facultyno'],
<?php
require_once('../ mydb_connect.php' );
$ query =SELECT distinct(s.specializationname)as'specialization',count(fs.facultyid)as'facultyno'from thesisdb.specialization s join facultyspecialization fs on s.specializationid = fs.specializationid group by s.specializationID;;
$ result = mysqli_query($ dbc,$ query);
while($ row = mysqli_fetch_array($ result)){
echo['。$ row ['specialization']。',。$ row ['facultyno']。],;
}
?>
]);
var options = {'title':'教师专业化数量',
'width':1300,
'height':900};
}
//实例化并绘制图表。
var chart = new google.visualization.ColumnChart(document.getElementById('no_of_specialization'));
chart.draw(data,options);
}
< / script>
< / head>
< body>
< div id =no_of_specialization/>
< / body>
< / html>
寻找问题时,我正在测试数据是否可以执行并且工作
这里是PHP代码
<?php
require_once ( '../mydb_connect.php');
$ query =SELECT distinct(s.specializationname)as specialization,count(fs.facultyid)as facultyno from thesisdb.specialization s join facultyspecialization fs on s.specializationid = fs.specializationid group by s.specializationID;;
$ result = mysqli_query($ dbc,$ query);
while($ row = mysqli_fetch_array($ result))
{
echo{$ row ['specialization']};
echo - ;
echo{$ row ['facultyno']}< br>;
}
?>
这是应在Google图表上显示的数据
我需要你的帮助。谢谢
代码中的每件事情都可以。但你正在使用一个额外的治疗大括号}。在这段代码后删除额外的括号'}'。
var options = {'title':'Faculty Specializations',
'width':1300,
'height':900};
如果您遇到问题以寻找额外的大括号}。只需复制并粘贴以下代码即可。
< html>
< head>
< script type =text / javascriptsrc =https://www.gstatic.com/charts/loader.js>< / script>
< script type =text / javascript>
google.charts.load('current',{packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
函数drawChart(){
//定义要绘制的图表。
var data = google.visualization.arrayToDataTable([
['Specialization','Facultyno'],
<?php
require_once('../ mydb_connect.php' );
$ query =SELECT distinct(s.specializationname)as'specialization',count(fs.facultyid)as'facultyno'from thesisdb.specialization s join facultyspecialization fs on s.specializationid = fs.specializationid group by s.specializationID;;
$ result = mysqli_query($ dbc,$ query);
while($ row = mysqli_fetch_array($ result)){
echo['。$ row ['specialization']。',。$ row ['facultyno']。],;
}
?>
]);
var options = {'title':'教师专业化数量',
'width':1300,
'height':900};
//实例化并绘制图表。
var chart = new google.visualization.ColumnChart(document.getElementById('no_of_specialization'));
chart.draw(data,options);
}
< / script>
< / head>
< body>
< div id =no_of_specialization/>
< / body>
< / html>
I'm creating a simple chart using Google Charts. I am using PHP and MYSQL when executing data. I was searching for answers and tried but it does not display the chart
Here is my test.php file
<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.setOnLoadCallback(drawChart);
function drawChart() {
// Define the chart to be drawn.
var data = google.visualization.arrayToDataTable([
['Specialization', 'Facultyno'],
<?php
require_once('../mydb_connect.php');
$query="SELECT distinct(s.specializationname) as 'specialization', count(fs.facultyid) as 'facultyno' from thesisdb.specialization s join facultyspecialization fs on s.specializationid=fs.specializationid group by s.specializationID;";
$result = mysqli_query($dbc,$query);
while($row = mysqli_fetch_array($result)){
echo "['".$row['specialization']."',".$row['facultyno']."],";
}
?>
]);
var options = {'title':'Number of Faculty Specializations',
'width':1300,
'height':900};
}
// Instantiate and draw the chart.
var chart = new google.visualization.ColumnChart(document.getElementById('no_of_specialization'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="no_of_specialization"/>
</body>
</html>
When looking for the problem, I was testing if the data can be executed and It worked
here is the php code
<?php
require_once('../mydb_connect.php');
$query="SELECT distinct(s.specializationname) as specialization, count(fs.facultyid) as facultyno from thesisdb.specialization s join facultyspecialization fs on s.specializationid=fs.specializationid group by s.specializationID;";
$result = mysqli_query($dbc,$query);
while($row = mysqli_fetch_array($result))
{
echo "{$row['specialization']}";
echo " - ";
echo "{$row['facultyno']}<br>";
}
?>
This is the data that should be displayed on Google Charts
I need your help. Thanks
Every thing is ok in your code. but you are using one extra curely braces "}". remove the extra curely braces '}' after this code.
var options = {'title':'Number of Faculty Specializations',
'width':1300,
'height':900};
if you faced problem to finding the extra curely braces "}". just copy and paste below code.
<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.setOnLoadCallback(drawChart);
function drawChart() {
// Define the chart to be drawn.
var data = google.visualization.arrayToDataTable([
['Specialization', 'Facultyno'],
<?php
require_once('../mydb_connect.php');
$query="SELECT distinct(s.specializationname) as 'specialization', count(fs.facultyid) as 'facultyno' from thesisdb.specialization s join facultyspecialization fs on s.specializationid=fs.specializationid group by s.specializationID;";
$result = mysqli_query($dbc,$query);
while($row = mysqli_fetch_array($result)){
echo "['".$row['specialization']."',".$row['facultyno']."],";
}
?>
]);
var options = {'title':'Number of Faculty Specializations',
'width':1300,
'height':900};
// Instantiate and draw the chart.
var chart = new google.visualization.ColumnChart(document.getElementById('no_of_specialization'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="no_of_specialization"/>
</body>
</html>
这篇关于使用php和sql时,Google Charts不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!