我想用Django(Mac maverick)创建一个具有HighCharts的饼图。解析json.dumps到Django的HighCharts
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有2个键,body - string值 - 和id__cout - 整数值。 但是,在模板中,我没有得到如何在HighCharts的数据中输入response_pie_json。 我正在尝试使用
data: {{ responses_pie_json|safe }}
但它只是显示一个空白屏幕。我该怎么办?
你的json是怎么样的?你在json中使用数字还是只使用字符串? –