Django使用Query和to_json绘制Google图形

Django使用Query和to_json绘制Google图形,django,graph,to-json,Django,Graph,To Json,我想绘制一个googlegraph来可视化查询结果 有人能帮我吗?我在下面包含了我的代码。谢谢 models.py class InventoriesApplication(models.Model): ROADMAPS = ( ('R', 'Retire'), ('SU', 'Sustain'), ('ST', 'Strategic') ) app_name = models.CharField(max_length=45

我想绘制一个
googlegraph
来可视化查询结果

有人能帮我吗?我在下面包含了我的代码。谢谢

models.py

class InventoriesApplication(models.Model):
    ROADMAPS = (
        ('R', 'Retire'),
        ('SU', 'Sustain'),
        ('ST', 'Strategic')
    )
    app_name = models.CharField(max_length=45)
    roadmap = models.CharField(max_length=2, choices=ROADMAPS, null = True)
import json
views.py

class InventoriesApplication(models.Model):
    ROADMAPS = (
        ('R', 'Retire'),
        ('SU', 'Sustain'),
        ('ST', 'Strategic')
    )
    app_name = models.CharField(max_length=45)
    roadmap = models.CharField(max_length=2, choices=ROADMAPS, null = True)
import json
我使用以下代码序列化我的查询:

def render_chart(request):
    total= InventoriesApplication.objects.values("roadmap").annotate(total=Count('id'))
    return HttpResponse(json.dumps(list(total), cls=DjangoJSONEncoder),content_type='charts.html')
现在我有了以下数组:

charts.html
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = google.visualization.arrayToDataTable({{ total }});                                          

        // Set chart options
        var options = {'title':'Roadmaps'};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>
charts.html
//加载可视化API和piechart包。
load('visualization','1.0',{'packages':['corechart']});
//将回调设置为在加载Google Visualization API时运行。
setOnLoadCallback(drawChart);
//创建并填充数据表的回调,
//实例化饼图,传入数据并
//画它。
函数绘图图(){
//创建数据表。
var data=google.visualization.arrayToDataTable({{total}});
//设置图表选项
var options={'title':'roadmap'};
//实例化并绘制图表,传入一些选项。
var chart=new google.visualization.PieChart(document.getElementById('chart_div');
图表绘制(数据、选项);
}

我想你说的是什么?没错。我走对了吗?