Sunday, December 22, 2013

Parsing json.dumps to HighCharts in Django

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?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bf1850c2-5849-49f0-973f-436d8e12e9ee%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment