admin管理员组文章数量:1427773
I have task to insert dynamic data to Google PieChart
.
Playground
In that link I insert this code:
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.DataTable();
var mycars=["Saab","Volvo","BMW"];
var mypoints=[4,12,45];
data.addColumn('string', 'Cars');
data.addColumn('number', 'Numbers');
data.addRows(mycars.length);
for (var i = 0; i < mycars.length; i++){
data.setCell(i,0,mycars[i]);
data.setCell(i,1,mypoints[i]);
}
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"So, how was your day?"});
}
In the following example I get dynamic arrays mycars
and mypoints
, then I try to insert those arrays to chart within for loop
.
PieChart isn't displaying. What's wrong with that?
I have task to insert dynamic data to Google PieChart
.
Playground
In that link I insert this code:
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.DataTable();
var mycars=["Saab","Volvo","BMW"];
var mypoints=[4,12,45];
data.addColumn('string', 'Cars');
data.addColumn('number', 'Numbers');
data.addRows(mycars.length);
for (var i = 0; i < mycars.length; i++){
data.setCell(i,0,mycars[i]);
data.setCell(i,1,mypoints[i]);
}
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"So, how was your day?"});
}
In the following example I get dynamic arrays mycars
and mypoints
, then I try to insert those arrays to chart within for loop
.
PieChart isn't displaying. What's wrong with that?
Share Improve this question edited Feb 4, 2013 at 22:04 Bruno Croys Felthes 1,2039 silver badges29 bronze badges asked Feb 4, 2013 at 21:35 Denisas KnelisDenisas Knelis 913 silver badges7 bronze badges2 Answers
Reset to default 3You have a javascript error. You need to use the new
keyword when instantiating the DataTable.
Replace
var data = google.visualization.DataTable();
with
var data = new google.visualization.DataTable();
I resolved the problem using code in jquery like this :
$("#piechart_3d").show();
google.load("visualization", "1", {
packages: ["corechart"], callback: function () {
var data = google.visualization.arrayToDataTable([
['Going', 'a Day'],
['Car', 11],
['Bus', 2],
['Moto', 2]
]);
var options = {
title: 'Report',
backgroundColor: 'transparent',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
});
本文标签: javascriptInserting dynamic data into Google Pie ChartStack Overflow
版权声明:本文标题:javascript - Inserting dynamic data into Google Pie Chart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745500072a2660988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论