我正在尝试使用谷歌图表api创建一个饼图。我希望从django 视图获取图表的数据。我使用下面的代码,但我没有得到任何图表。
views.py
def demo_piechart(request):
rRows = Verification.objects.filter(status=1).count()
vRows = Verification.objects.filter(status=2).count()
tRows = Verification.objects.filter(status=3).count()
print rRows,vRows,tRows
data={'values': [['Verified', vRows], ['Tampered', tRows], ['Registered', rRows]]}
return render_to_response('piechart.html',data
)
pichart.html
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var djangoData = {{ data|safe }};
var data = google.visualization.arrayToDataTable(djangoData);
var options = {
title: 'Chart Title'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
任何解决方案......