1
我想通過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>