我在使用 django-graphos 显示图表时遇到问题。我已经根据文档进行了尝试。它没有在 x 轴中显示站点名称,并且图表上也没有绘图:
我的代码:
模型.py
class MonthlySiteResponse(models.Model):
site_name = models.CharField(max_length=30)
response_time = models.FloatField()
View .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})
图.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 模型查询集一起使用的任何其他包吗?
最佳答案
我对 Django-graphos
一无所知,所以这是一个 WAG,但请尝试:
chart = flot.BarChart(data_source, options={'title': "Website", 'xaxis': {'mode': "categories"}})
关于django - 使用 Django-graphos 显示图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22419375/