gpt4 book ai didi

javascript - 无法纠正 php 语法错误

转载 作者:行者123 更新时间:2023-12-01 04:00:33 25 4
gpt4 key购买 nike

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

意外的 token {

<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]

最佳答案

从代码中删除 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"]
]);

关于javascript - 无法纠正 php 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com