使用Django-Graphos显示图形 [英] Displaying graphs using Django-graphos

查看:263
本文介绍了使用Django-Graphos显示图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 django-graphos 显示图表时遇到问题。我已经按照documentation.its的方式尝试过了,它没有在x轴上显示网站名称,也没有在图表上显示图表:

我的代码:



models.py

  class MonthlySiteResponse(models.Model):

site_name = models.CharField(max_length = 30)
response_time = models.FloatField()

views.py

  def fn(请求):

site_response_details = {'Site A ':1.864,'Site B':2.086,'Site C':2.873,'Site D':2.22}


#在我的模型字段中保存数据
,site_response.items()中的值:
new = MonthlySiteResponse()
new.site_name = name
new.response_time = value $ b $ new.save()

queryset = MonthlySiteResponse.objects.all()
data_source = ModelDataSource(queryset,fields = ['site_name', 'response_time'])

chart = flot.BarChart(data_source,options = {'title':Website})

return render_to_response(graphs.html, {chart:chart})

graph.html

 < html xmlns =http://www.w3.org/1999/xhtml> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
{%load static%}
< script type =text / javascriptsrc ={%get_static_prefix%} js / jquery.js>< / script>
< script src ={%get_static_prefix%} js / flot / jquery.flot.jstype =text / javascript>< / script>
< script src ={%get_static_prefix%} js / flot / jquery.flot.categories.jstype =text / javascript>< / script>

< / head>

< body>
{{chart.as_html}}
< / body>
< / html>

任何人都可以推荐任何其他包与Django模型queryset一起使用吗?我不知道任何关于 Django-graphos ,所以这是一个WAG,但尝试:

  chart = flot.BarChart(data_source,options = {'title':Website,'xaxis':{' mode':categories}})


I am having problem while displaying graphs with django-graphos. I have tried according to the documentation.its not showing the site names in the x-axis and also no plots on the graph :

my code :

models.py

    class MonthlySiteResponse(models.Model):

        site_name     = models.CharField(max_length=30)
        response_time = models.FloatField()

views.py

    def fn(request) :

        site_response_details = {'Site A' : 1.864, 'Site B' : 2.086, 'Site C' : 2.873, 'Site D' : 2.22 }


        #Saving data in my model fields
        for name, value in site_response.items() :
            new = MonthlySiteResponse()
            new.site_name = name
            new.response_time = value
            new.save()

        queryset = MonthlySiteResponse.objects.all()
        data_source = ModelDataSource(queryset, fields= ['site_name', 'response_time'])

        chart = flot.BarChart(data_source, options={'title': "Website"})

        return render_to_response("graphs.html", {"chart": chart})

graph.html

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        {% load static %}
        <script type="text/javascript" src="{% get_static_prefix %}js/jquery.js"></script>
        <script src="{% get_static_prefix %}js/flot/jquery.flot.js" type="text/javascript"></script>
        <script src="{% get_static_prefix %}js/flot/jquery.flot.categories.js" type="text/javascript"></script>

    </head>

    <body>
        {{chart.as_html}}
    </body>
    </html>

Can anyone suggest any other package to be used with Django models queryset?

解决方案

I don't know anything about Django-graphos, so this is a WAG, but try:

 chart = flot.BarChart(data_source, options={'title': "Website", 'xaxis': {'mode': "categories"}})

这篇关于使用Django-Graphos显示图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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