我想添加多个数据值在我的饼图采取模型字段。目前我是这样做的:
def detail(request, pk):
if not request.user.is_authenticated():
return render(request, 'registration/login.html')
else:
bowler = Bowlers.objects.get(pk=pk)
select_list = UserSelect.objects.filter(user=request.user, bowler=pk)
all_select = UserSelect.objects.filter(user=request.user).count()
team = Team.objects.filter(user=request.user)
dataSource = {}
dataSource['chart'] = {
"caption": "last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenues (In USD)",
"numberPrefix": "$",
"theme": "zune",
"type": "doughnut2d"
}
dataSource['data'] = []
# Iterate through the data in `Revenue` model and insert in to the `dataSource['data']` list.
data = {}
data['label'] = bowler.name
data['value'] = bowler.ave
dataSource['data'].append(data)
column2D = FusionCharts("doughnut2d", "ex1", "600", "350", "chart-1", "json", dataSource)
context = {
'bowler': bowler,
'select_list': select_list,
'all_select': all_select,
'team': team,
'output': column2D.render()
}
return render(request, 'bowler_detail.html', context)
我想添加更多的值,像这样:(这是添加多个数据值的JSON格式)
"data": [
{
"label": "Venezuela",
"value": "290"
},
{
"label": "Saudi",
"value": "260"
},
]
有什么指南可以指导我如何在图表中添加更多从django模型获取的值吗?
1条答案
按热度按时间qnakjoqk1#
饼图的示例代码-
另请参阅使用API的切片数据图-https://www.fusioncharts.com/dev/getting-started/django/slice-data-plot-using-custom-api-in-django