在我的游戏应用程序中,我向视图发送一些JSON输出,以显示Google饼图。呈现js时出错
Object {cols: [{id: 'title', label: 'Title' , type: 'string'},{id: 'unitPrice', label: 'Unit Price', type: 'int'}],rows: [ has no method 'getColumnType'×
这是我尝试使用Google Chart API绘制饼图所得到的全部信息。
这到底是什么意思? “没有方法'getColumnType'”
任何见识都将得到极大的应用。到目前为止,我的代码:
<!DOCTYPE html>
<html>
<head>
<title>PayView</title>
<head>
<script type="text/javascript">var pieChartData;</script>
<script type="text/javascript">var loads = 0;</script>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(function() {
++loads;
if (loads == 2)
drawVisualization();
});
function drawVisualization() {
$('.log').html('pieChartData: ' + pieChartData);
new google.visualization.PieChart(document.getElementById('visualization')).
draw(pieChartData, {title:"Purchases"});
}
$(document).ready(function() {
$(function() {
pieChartData = new google.visualization.DataTable();
pieChartData.addColumn('string', 'Title');
pieChartData.addColumn('number', 'Unit Price');
var getJSon2 = $.ajax({
url: '@routes.Application.getJson()',
processData:false,
type: 'GET',
beforeSend:function(jqXHR, settings){
jqXHR.setRequestHeader("Content-Type", "application/json");
},
success: function(data, textStatus, jqXHR){
++loads;
if (loads == 2)
drawVisualization();
process_items(data);
},
error: function(jqXHR, textStatus, errorThrown){
},
complete: function(jqXHR,textStatus){
}
);
var process_items = function(data){
pieChartData.addRows(data.length);
$.each(data, function(index, item) {
$("#purchases").append("<li>" + item.name + "</li>");
pieChartData.setCell(index, 0, item.title);
pieChartData.setCell(index, 1, item.unitPrice);
});
});
});
};
});
</script>
</head>
<body>
<div class="log"></div>
<div id="purchases"></div>
<div id="visualization" style="width: 500px; height: 300px;"></div>
</body>
</html>
最佳答案
您也可以给函数指定参数
function drawChart(draw)
{
if(draw > 0)
{
var data=....;
var options = ....;
var chart = ....;
chart.draw(data,options)
}
}
然后在ajax中调用此函数,并给出类似
drawChart(1)
的值关于javascript - 对象没有方法getColumnType,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11376665/