我在codeigniter中创建饼图。我的问题是它只显示一个值。我需要StockValuebyCost和StockValuebyPrice两个,根据我的代码,它只显示一个值StockValuebyCost,帮我如何显示StockValuebyCost和StockValuebyPrice。
MYmodel
function getStock(){
$this->db->select('sum(quantity * cost_price)As StockValuebyCost,
sum(quantity * unit_price)As StockValuebyPrice');
$this->db->from('items');
$this->db->join('item_quantities', 'items.item_id = item_quantities.item_id');
$this->db->where('deleted', 0);
return $this->db->get()->result(); // Return the results in a array.
}
MY Controller
function getdata()
{
$data = $this->home_model->getStock();
$responce->cols[] = array(
"id" => "",
"label" => "Topping",
"pattern" => "",
"type" => "string"
);
$responce->cols[] = array(
"id" => "",
"label" => "Total",
"pattern" => "",
"type" => "number"
);
foreach($data as $cd)
{
$responce->rows[]["c"] = array(
array(
"v" => "StockValuebyCost",
"f" => null
) ,
array(
"v" => (int)$cd->StockValuebyCost,
"f" => null
)
);
}
echo json_encode($responce);
}
我的观点js
// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "<?php echo base_url() . 'index.php/home/getdata' ?>",
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: 700, height: 500});
}