Ajax를 사용하여 Google Chart를로드하려고하는데 어떤 이유로 전달되는 데이터에 배열이 아니라고 표시됩니다.Google 차트; 잡히지 않은 오류 : 배열이 아닙니다.
내가 디스플레이로 차트에 대한하려는 페이지에 자바 스크립트 여기에 있습니다 :이
<script>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawCharts);
function drawCharts(){
// Each chart function
$.get('charts_ajax.php',{a : 'usage'}, function(data){
if(data){
initGoogleChart(data)
}
});
}
function initGoogleChart(data){
var tableData = google.visualization.arrayToDataTable(data);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('terms-table'));
chart.draw(tableData, options);
}
</script>
그리고 charts_ajax.php 파일에 있습니다 :
if ($_GET['a'] == "usage") {
$arrTableData = array([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
echo $arrTableData;
}
내가 CONSOLE.LOG ($ arrTableData) 얻을 수 있습니다 :
array(1) {
[0]=>
array(6) {
[0]=>
array(2) {
[0]=>
string(4) "Task"
[1]=>
string(13) "Hours per Day"
// etc etc..
그래서 왜 배열이 없다는 말을하고 그것이 왜 작동하지 않습니까?
지금 잡았습니다 : 잡히지 않은 SyntaxError : 예기치 않은 토큰 – MarkP
무엇이 완전한 오류 메시지입니까? 그것은 PHP 또는 JavaScript에 있습니까? – Latheesan
javascript 및 그 : Uncaught SyntaxError : 예기치 않은 토큰 T? nav-filter = all : 1631 initGoogleChart? nav-filter = all : 1631 (익명 함수) nav-filter = all : 1616 c jquery-combined.js? 12 : 8 p.fire와 jquery-combined.js? 12 : 8 k jquery-combined.js? 12 : 10 r – MarkP