Parsing json.dumps to HighCharts in Django

67 views
Skip to first unread message

Filipe Ferminiano Rodrigues

unread,
Dec 23, 2013, 1:07:34 AM12/23/13
to django...@googlegroups.com

I'm trying to create a pie chart with HighCharts with Django (Mac maverick).

This is my views.py

    def piechart(request):
        responses_pie =  AnswerRadio.objects.values("body").annotate(Count("id"))
        res = []
        for cat in responses_pie:
            res.append([
                cat["body"],    
                cat["id__count"],
                ])
        return render(request, 'chart_code_v2.html', {'responses_pie_json': json.dumps(res)})

reponses_pie_json has 2 keys, body - string values - and id__cout - integer values. But, in template, I'm not getting how to input response_pie_json in data of HighCharts. I'm trying to use

data: {{ responses_pie_json|safe }}

But It just show a blank screen. What should i do?

Reply all
Reply to author
Forward
0 new messages