2017-09-15 50 views
0

我正在使用Django ChartitCassandra 3.0显示图表是我的数据库。在我的浏览器上获取{%load chartit%}。图表未使用图表加载

我试图渲染折线图,但它没有显示图形,而是显示{% load chartit %}。请提出建议。我使用了Google,但没有帮助。

我认为HTML中的代码是正确的。但我不知道什么是错的。

以下是补充:

Models.py

# -*- coding: utf-8 -*- 
from __future__ import unicode_literals 

# -*- coding: utf-8 -*- 

from django.db import models 

# Create your models here. 

from cassandra.cqlengine import columns 
from django_cassandra_engine.models import DjangoCassandraModel 


class PqpModel(DjangoCassandraModel): 

    prd_id = columns.BigInt(primary_key=True) 

    X_01 = columns.Decimal() 

    X_02 = columns.Decimal() 

    X_03 = columns.Decimal() 

    X_04 = columns.Decimal() 

    X_05_1 = columns.Decimal() 

    X_05_10 = columns.Decimal() 

    X_05_11 = columns.Decimal() 

    X_05_12 = columns.Decimal() 

urls.py

from django.conf.urls import url, include 

from . import views 

urlpatterns = [ 
    url(r'^$', views.index, name='index'), 
] 

views.py

# -*- coding: utf-8 -*- 
from __future__ import unicode_literals 

from django.shortcuts import render 

from django.db import models 

from cassandra.cqlengine import connection 

from cassandra.cqlengine.management import sync_table 

from cassandra.cluster import Cluster 

from chartit import DataPool, Chart 

from models import PqpModel 

from django.http import HttpResponse 


# Create your views here. 

from django.http import HttpResponse 

# def index(request): 
#  cluster = Cluster(['127.0.0.1']) 
#  session = cluster.connect() 
#  session.set_keyspace('samplepqp') 
    #return HttpResponse(session.execute("""SELECT * FROM qsp_recreate""")) 
    # insert = PqpModel(prd_id="7859654564465465") 
    # insert.save() 
    # cluster.shutdown() 

def pqp_line_chart(request): 
     cluster = Cluster(['127.0.0.1']) 
     session = cluster.connect() 
     session.set_keyspace('samplepqp') 
     cluster.shutdown() 
     #1: Create a DataPool or PivotDataPool object that specifies what data you need to retrieve and from where. 
     ds = DataPool(
      series=[{'options': { 
       'source': PqpModel.objects.all()}, 
       'terms': [ 
        'prd_id', 
        'X_01', 
        'X_05_1']} 
      ]) 

     # Step 2: Create the Chart object 

     cht = Chart(

      datasource=ds, 

      series_options= 
      [{ 
       'options': { 

        'type': 'line', 
        'stacking': False}, 
       'terms': { 
        'prd_id': [ 
         'X_01', 
         'X_05_1'] 

       }}], 

      chart_options= 
      {'title': { 
       'text': 'QSPRAW DATA 7'}, 
       'xAxis': { 
        'title': { 
         'text': 'prd id data'}}}) 

     #return render({'qspraw7_data/index.html': cht}) 

     return render(request, {'pqpchart': cht}) 

的index.html

<html> 
<head> 
<script type=”text/javascript” src=”/media/js/jquery-1.7.1.js”></script> 
<script type=”text/javascript” src=”/media/js/Highcharts-2.1.9/js/highcharts.js”></script> 
{% load chartit %} 

</head> 
<body> 
<div id=”container”> 
    {{ pqpChart|load_charts:”container” }} 
    </div> 
</body> 
</html> 

回答

0

你的HTML模板应该是这样的:

<head> 
<script type=”text/javascript” src=”/media/js/jquery-1.7.1.js”></script> 
<script type=”text/javascript” src=”/media/js/Highcharts-2.1.9/js/highcharts.js”></script> 
{% load chartit %} 
{{ pqpChart|load_charts:"container" }} 
</head> 
<body> 
<div id=”container”> 
</div> 
</body> 

,然后视图应该返回正确的变量,以区分大小写的名字。在你的例子中使用您在HTML模板中使用相同的大小写:

return render(request, {'pqpChart': cht}) 
+0

嗨亚历山大,我已经根据你的建议做出了改变。但是图表并没有渲染,我在浏览器中得到了这个结果:“{%load chartit%} {{pqpChart | load_charts:”container“}}”请说清楚一些。 –

+0

更多建议请! –

+0

我现在正在 - >在我的浏览器中,很奇怪! –

相关问题