2015-06-19 79 views
0

我是Django的新手。我想用django graphos繪製一個谷歌圖。我已經寫小代碼爲和我得到空template..any鉛會appritiated ..使用Django-Graphos繪製圖形時的空模板

view.py

from graphos.renderers import gchart 
from django.shortcuts import render 
from django.shortcuts import render_to_response 
from graphos.sources.model import ModelDataSource 
from models import MyCityViews 

def get_context_data(self): 
    queryset = MyCityViews.objects.all() 
    data_source = ModelDataSource(queryset,fields=['city', 'views']) 
    line_chart = gchart.LineChart(data_source) 
    context = {"chart": line_chart} 
    return render_to_response('gchart.html', {'chart': line_chart}) 

models.py

from django.db import models 

# Create your models here. 
class MyCityViews(models.Model): 
    city = models.CharField(max_length = 30, blank = True , null = True) 
    views = models.IntegerField() 

    class Meta: 
     ordering = ['city'] 
     verbose_name = 'city' 
     verbose_name_plural = 'city' 

    def __unicode__(self): 
     return self.city 

gchart.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <meta charset="utf-8"> 
    <title>Graphos</title> 
    {% load static from staticfiles %} 

    <link rel="stylesheet" href="{% static "css/bootstrap.css" %}"> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
    google.load("visualization", "1", {packages:["corechart"]}); 
    google.setOnLoadCallback({{line_chart.as_html}}); 
    </script> 
</head> 

<body> 
{{line_chart.as_html}} 
<div id="container"></div> 
</body> 
</html> 

我在哪裏做錯了...

回答

0

沒有傳遞視圖對象到div塊這就是爲什麼我沒有得到HTML視圖。

<body> 
<div id="container"> 
{{line_chart.as_html}} 
</div> 
</body>