我试图让谷歌图表显示在我的页面上,但我不知道如何将值从 django 视图传递到 javascript,以便我可以绘制图表。
姜戈代码:
array = ([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
args['array']= array
return render_to_response('progress.html',args)
进度.html:
<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 = '{{array}}';
var data = google.visualization.arrayToDataTable(djangoData);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
这样,图表就不会显示。有什么建议么 ?