Displaying graphs using Django-graphos
Asked Answered
G

2

2

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?

Glut answered 15/3, 2014 at 4:4 Comment(0)
E
2

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"}})
Erie answered 15/3, 2014 at 13:24 Comment(1)
Your solution works. Need to further enhance my code from here onwards. ThanksGlut
W
1

What platform are you trying this on ? Have you tried running the demo site from graphos available on github ?

to run the Demo site

  1. go to/django-graphos/demo_project/demo_project/settings/
  2. $cp local.py-dist local.py
  3. Change your directory to /django-graphos/demo_project/
  4. $pip install -r requirements.txt
  5. run the local server by going to go to /django-graphos/demo_project/
  6. $python manage.py runserver
  7. check the demo by visiting localhost:8000 in your browser.

This will give you fairly good idea how Django-graphos can be used, if you face any issues do ask.

Winchell answered 18/3, 2014 at 7:18 Comment(1)
Thanks for the steps. Will try and let you know in case of any issues.Glut

© 2022 - 2024 — McMap. All rights reserved.