无法纠正语法错误php

时间:2017-02-14 14:38:30

标签: javascript php wordpress google-chartwrapper

我正在使用谷歌图表,发现语法错误

意外令牌{

<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([
['name', 'score'],
<?php 
global $wpdb;
$query = $wpdb->get_results("select t2.name, count(t1.id) as score from wp3_wpsp_custom_status as t2 left join wp3_wpsp_ticket as t1 on t2.name =   t1.status group by t2.name");
var_dump($query);
foreach($query as $row){
$object_array =(array)$row;
echo "['".$object_array['name']."',".$object_array['score']."],";
}
?>
]);
var options = {
title: 'Date wise visits'
};
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart"));
chart.draw(data, options);
}
</script>

以上代码是创建柱形图的基本语法。查看“var data = google.visualization.arrayToDataTable”之后的值([“这个值有静态值。但为了显示我们的统计数据,我们需要使用php从我们的数据库中动态加载这些值。

<body>
<h3>Column Chart</h3>
<div id="columnchart" style="width: 900px; height: 500px;"></div>
</body>

错误[![在此处输入图像说明] [1]] [1]

1 个答案:

答案 0 :(得分:2)

从代码中删除var_dump($query)

要添加颜色,请添加第三个参数。他们网站的例子:

var data = google.visualization.arrayToDataTable([
        ["Element", "Density", { role: "style" } ],
        ["Copper", 8.94, "#b87333"],
        ["Silver", 10.49, "silver"],
        ["Gold", 19.30, "gold"],
        ["Platinum", 21.45, "color: #e5e4e2"]
      ]);