我在使用django-graphos显示图表时遇到问题。我根据文档尝试过。没有在x轴上显示网站名称,也没有在图表上显示图:
我的代码:
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>
有人可以建议任何其他包用于Django模型查询集吗?
答案 0 :(得分:2)
我对[{1}}一无所知,所以这是一个WAG,但请尝试:
Django-graphos
答案 1 :(得分:1)
你在尝试这个平台?您是否尝试过使用graphos available on github运行演示网站?
运行演示网站
/django-graphos/demo_project/demo_project/settings/
$cp local.py-dist local.py
/django-graphos/demo_project/
$pip install -r requirements.txt
/django-graphos/demo_project/
$python manage.py runserver
localhost:8000
查看演示。如果您遇到任何问题,这将为您提供如何使用Django-graphos的相当好的建议。