0

我正在尝试google charts使用ajax响应表单PHP文件进行构建。以下是alert我的输出javascript

{"cols":[{"id":"5","label":"LISTING","type":"number"}],"rows":[{"c":[{"v":"1"}]}]}

当我使用以下代码构建图表时,我得到了错误Data table is not defined.

function drawBarChartAll(totalclientstatus) {
        alert(totalclientstatus);
        //eval ( 'var jsonobject = totalclientstatus;'); 
        //var json = google.visualization.DataTable.toJSON(totalclientstatus)
        var data = google.visualization.DataTable(totalclientstatus);

        var options = {
            'width':670,
            'height':310,

            hAxis: {title: 'Year',  titleTextStyle: {color: 'red'}}
            //chartArea:{left:20,top:20,width:"70%",height:"100%"}
        };


        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.ColumnChart(document.getElementById('barchartall'));
        chart.draw(data, options);
    }

我究竟做错了什么 ?我正在使用以下内容php来构建JSON

while ($row = mysqli_fetch_array($agent_result, MYSQL_ASSOC))
    {
        $columns = array();
        $reports['cols'][] = array(id => "{$row['statusid']}"
            , label => "{$row['status']}"
            , type => "number");
        $columns['c'][] = array(v => $row['total']);
        $reports['rows'][] = $columns;
    }
 return json_encode($reports);

ajax回应是

{"totalclientstatus":"{\"cols\":[{\"id\":\"5\",\"label\":\"LISTING\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"1\"}]}]}"}
4

1 回答 1

9

我猜你错过了“新”:

var data = new google.visualization.DataTable( ...

于 2012-09-26T02:09:45.110 回答