使用CodeIgniter基于JSON数据创建Google饼图 [英] Creating Google Pie Chart based on JSON data using CodeIgniter
问题描述
我尝试根据示例此处创建饼图
在我的控制器(mycontroller / json)中,我有以下代码:
public function json(){
$ whatever ='{
cols:[
{id:,label:Topping,pattern :type:string},
{id:,label:Slices,pattern:,type:number}
,
rows:[
{c:[{v:Mushrooms,f:null},{v:3,f :null}],
{c:[{v:Onions,f:null},{v:1,f:null}]},
{c:[{v:Olives,f:null},{v:1,f:null}]},
{c:[ {v:Zucchini,f:null},{v:1,f:null}]},
{c:[{v:Pepperoni ,f:null},{v:2,f:null}]}
]
}';
echo $ whatever;
$ b $ p
$ b 在我看来,我有以下代码(部分代码显示) p>
var jsonData = $ .ajax({
url:<?= base_url()?> index.php / bunker / json,
dataType:json,
async:false
})。responseText;
//创建并填充数据表。
var popularCategory = google.visualization.DataTable(jsonData);
new google.visualization.PieChart(document.getElementById('category'))。draw(popularCategory,
{title:Popularity by Category});
最后,我有一个名为'category'的id的div。但是,我总是会收到一条消息,说数据没有被定义。
使用萤火虫进行快速调试,我收到了没有错误的消息,$ whatever变量也被视为正确的JSON格式。我在这里犯了什么错误?
干杯,
解决方案改为:
var popularCategory = google.visualization.DataTable(jsonData);
您必须拥有:
var popularCategory = new google.visualization.DataTable(jsonData);
I tried to create a pie chart based on example here
In my controller (mycontroller/json) i have the following code:
public function json(){
$whatever = '{
"cols": [
{"id":"","label":"Topping","pattern":"","type":"string"},
{"id":"","label":"Slices","pattern":"","type":"number"}
],
"rows": [
{"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
{"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}
]
}';
echo $whatever;
}
In my view i have the following code (partial code is shown)
var jsonData = $.ajax({
url: "<?= base_url()?>index.php/bunker/json",
dataType:"json",
async: false
}).responseText;
// Create and populate the data table.
var popularCategory = google.visualization.DataTable(jsonData);
new google.visualization.PieChart(document.getElementById('category')).draw(popularCategory,
{title:"Popularity by Category"});
And lastly i have a div with an id called 'category'. However, i always get a message saying data is not defined.
A quick debug using firebug, i receive no error, the $whatever variable is also treated as a proper JSON format. What mistakes have i made here?
cheers,
解决方案 instead of:
var popularCategory = google.visualization.DataTable(jsonData);
you must have:
var popularCategory = new google.visualization.DataTable(jsonData);
这篇关于使用CodeIgniter基于JSON数据创建Google饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!