无法读取属性谷歌图表


Cannot read property google charts

我想通过JSON设置谷歌图表,但目前它不起作用。网页它的说法不能读取未定义的"1"的属性。如何解决这个问题?提前感谢这是我的代码:

测试目的:(型号)

    $table = array();
    $table['cols'] = array(
        array('label' => 'Name', 'type' => 'string'),
        array('label' => 'Value', 'type' => 'number')
    );
    $PR = $CO = $IN = $SP = $SC = 5;

    $temp[] = array('v' => 'PR'); 
    $temp[] = array('v' => $PR);
    $temp[] = array('v' => 'CO'); 
    $temp[] = array('v' => $CO);
    $temp[] = array('v' => 'SCC'); 
    $temp[] = array('v' => $SC);
    $temp[] = array('v' => 'IN'); 
    $temp[] = array('v' => $IN);
    $temp[] = array('v' => 'SP'); 
    $temp[] = array('v' => $SP);
    $table['rows'] = $temp;
    return $table;

控制器:

    public function getProjects(){
    $this->load->model('mreport');
    $results = $this->mreport->getBilling();
    echo json_encode($results);
}

.HTML:

   <?php ?>
<html>
<head>
    <script type="text/javascript" src="<?php echo base_url() . 'resources/js/jquery-1.9.1.js' ?>"></script>
    <script type="text/javascript" src="<?php echo base_url() . 'resources/js/jquery-ui-1.10.3.custom.js' ?>"></script>
    <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 jsonData = $.ajax({
                url: "<?php echo site_url('report/getProjects'); ?>",
                dataType: "json",
                async: false
            }).responseText;
            // Create our data table out of JSON data loaded from server.
            var data = new google.visualization.DataTable(jsonData);
            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            chart.draw(data, {width: 400, height: 240});
        }
        var options = {
            title: 'Pie chart',
            is3D: true,
        };
    </script>
</head>
<body>
    <div id="chart_div"></div>
</body>

JSON 字符串的配置不正确。 试试这个:

$table = array();
$table['cols'] = array(
    array('label' => 'Name', 'type' => 'string'),
    array('label' => 'Value', 'type' => 'number')
);
$PR = $CO = $IN = $SP = $SC = 5;
$table['rows'] = array();
$temp = array();
$temp[] = array('v' => 'PR'); 
$temp[] = array('v' => $PR);
$table['rows'][] = array('c' => $temp);
$temp = array();
$temp[] = array('v' => 'CO'); 
$temp[] = array('v' => $CO);
$table['rows'][] = array('c' => $temp);
$temp = array();
$temp[] = array('v' => 'SCC'); 
$temp[] = array('v' => $SC);
$table['rows'][] = array('c' => $temp);
$temp = array();
$temp[] = array('v' => 'IN'); 
$temp[] = array('v' => $IN);
$table['rows'][] = array('c' => $temp);
$temp = array();
$temp[] = array('v' => 'SP'); 
$temp[] = array('v' => $SP);
$table['rows'][] = array('c' => $temp);
return $table;