django chartit没有图表显示,空浏览器屏幕 [英] django chartit no chart is showing, empty browser screen

查看:102
本文介绍了django chartit没有图表显示,空浏览器屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用django框架的Web应用程序,需要在前端绘制和显示图表。
所以我使用django chartit这个目的,但是当我运行django开发服务器,它显示没有空白的浏览器屏幕,也没有错误。
我失去了我做错了。

I am working on a web app using django framework where there is a need to draw and show charts on frontend. So i am using django chartit for this purpose, but when i run django development server, it shows nothing there is blank browser screen and no error also. I am lost what i have done wrong.

以下是渲染图形的视图

from chartit import DataPool,Chart
from django.template import RequestContext
from django.template import Context,loader
from django.shortcuts import render_to_response
from django.http import HttpResponse
from graphtest.apps.graph_app.models import charttest
def chartview(request):
    powerdata = DataPool(series=[{'options':{
        'source':charttest.objects.all()},
        'terms':[
            'power',
            'time']}])
    cht = Chart(datasource=powerdata,series_options=[{'options':
                                                          {'type':'line',
                                                           'stacking':False},
                                                          'terms':
                                                              {'time':['power',]}}],
        chart_options={
        'title':{
            'text':'power data'},
        'xAxis':{'title':{'text':'xaxis'}}})

    return render_to_response('graph.html',{'powerchart': cht})

制作图形的模型

from django.db import models

class charttest(models.Model):
    power = models.PositiveIntegerField()
    time = models.DecimalField(decimal_places=10,max_digits=20)
    def __unicode__(self):
        return unicode(self.power)+' '+unicode(self.time)

和模板

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="/static/js/highcharts.js"></script>
    <script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script type ="text/javascript" src ="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    {% load chartit %}
    {{ powerchart|load_charts:"container"}}

</head>
<body>
<div id="container"></div>
</body>
</html>

请帮助我,我停了好几个小时。
如果需要更多信息,请询问。

please help me out i am stuck for hours. If any more information is needed please ask.

推荐答案

尝试以下操作:

<div id="container">{{ powerchart|load_charts:"container"}}</div>

这篇关于django chartit没有图表显示,空浏览器屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆