agiliq / django-graphos

Django charting made *really* easy.
http://agiliq.com/demo/graphos
BSD 2-Clause "Simplified" License
442 stars 97 forks source link

Getting blank chart when trying to use ModelDataSource #21

Closed ShiftyRat closed 8 years ago

ShiftyRat commented 10 years ago

I'm getting a blank chart when I'm trying to pull data from a Django model. Here is the relevant code:

views.py:

    queryset = HisCorOsCompliance.objects.filter(facility='ALL')
    data_source = ModelDataSource(queryset, fields=['server_compliance', 'date'],)                          
    chart = morris.LineChart(data_source)      
    context = {'chart':chart}  

    return render(request, 'portal/index.html',  context)

html:

        {% if chart %}
        {{ chart.as_html }}
        {% endif %}

I'm getting a large, blank chart as a result. I can verify that the query is working correctly. if I do a "print data" within the get_field_values function within model.py, the console prints all of the values that I'm trying to display.

I've been able to get a chart working by using the SimpleDataSource. I'm sure there's something really basic that I'm overlooking, but I'm having a really hard time figuring it out. Any help is appreciated!

akshar-raaj commented 8 years ago

@prophecy0 It seems like you haven't included morris.js in your html. Can you check your javascript console? Probably, you would see "Uncaught ReferenceError: Morris is not defined" on the console.

Your html file should look like:

<link rel="stylesheet" href="http://cdn.oesmith.co.uk/morris-0.4.3.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdn.oesmith.co.uk/morris-0.4.3.min.js"></script>
{% if chart %}
{{chart.as_html}}
{% endif %} 
akshar-raaj commented 8 years ago

@prophecy0 I belive my last comment should resolve your issue, so closing this issue. Please feel free to reopen the issue if it is not resolved.