[英]How to get Jquery data to google pie chart?
I am trying to use my data for google Pie chart but its not working.我正在尝试将我的数据用于谷歌饼图,但它不起作用。
When I am using this code当我使用此代码时
var data = google.visualization.arrayToDataTable([
['ProductCategory', 'ItemsSold'],
[dit[0].CategoryName, dit[0].ItemsSold],
[dit[1].CategoryName, dit[1].ItemsSold],
[dit[2].CategoryName, dit[2].ItemsSold]
]);
It works as I am putting things statically, but when I am using my data in the loop and bind this way then no data appears in the chart它在我静态放置事物时起作用,但是当我在循环中使用我的数据并以这种方式绑定时,图表中不会出现任何数据
var data1=[];
var Header= ['ProductCategory', 'ItemsSold'];
data1.push(Header);
for (var i = 0; i < dit.length; i++) {
var temp = [];
temp.push(dit[i].CategoryName);
temp.push(parseInt(dit[i].ItemsSold));
data1.push(temp);
}
var data = google.visualization.arrayToDataTable([data1]);
Here, dit is my dictionary with CategoryName and ItemsSold.在这里,dit 是我的带有 CategoryName 和 ItemsSold 的字典。
One thing which I noticed is that when I am trying to check "data" in console, the header for former one had 2 types string and int but for the latter, the header contained my whole pairs of data as well.我注意到的一件事是,当我尝试在控制台中检查“数据”时,前一个的 header 有两种类型的字符串和 int,但对于后者,header 也包含我的整对数据。
Like this for when I used loop当我使用循环时就像这样
Like this for when I use the 1st way and it works当我使用第一种方式并且它有效时,就像这样
since you're starting with an array, here...因为你是从一个数组开始的,所以在这里......
var data1=[];
you do not need to surround with another array, here...你不需要用另一个数组包围,在这里......
var data = google.visualization.arrayToDataTable([data1]);
change to...改成...
var data = google.visualization.arrayToDataTable(data1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.