gpt4 book ai didi

javascript - 如何用Django-nvd3绘制圆环图

转载 作者:行者123 更新时间:2023-11-28 07:55:42 25 4
gpt4 key购买 nike

我正在使用 django-nvd3 作为可视化库,它们提供的支持图表数量有限。有什么方法可以自定义文档中提供的饼图,使其成为圆环图。

def statistics(request):
context=RequestContext(request)


xdata = ["Apple", "Apricot", "Avocado", "Banana", "Boysenberries", "Blueberries", "Dates", "Grapefruit", "Kiwi", "Lemon"]
ydata = [52, 48, 160, 94, 75, 71, 490, 82, 46, 17]
chartdata = {'x': xdata, 'y': ydata}
charttype = "pieChart"
chartcontainer = 'piechart_container'
data = {
'charttype': charttype,
'chartdata': chartdata,
'chartcontainer': chartcontainer,
'extra': {
'x_is_date': False,
'x_axis_format': '',
'tag_script_js': True,
'jquery_on_ready': False,
}
}
return render_to_response('App/statistics.html',data)

我可以通过这样设置来改变图表的大小:

{% include_container chartcontainer 426 400 %}

最佳答案

我自己只是偶然发现了这个问题。迟到总比不到好...

我刚刚查看了 donut 与普通 JS 的代码差异 (found here),并注意到额外的 4 个设置。

'labelThreshold':0.5,
'labelType':'percent',
'donut':True,
'donutRatio':0.35

所以我将它们放入 data 的“extra”部分,这似乎有效。

编辑:我注意到标签设置没有生效。浏览了几次页面源代码和 nvd3_tags.py 后,我意识到您需要引用 labelType 并将它们嵌入另一个名为 chart_attr 的字典中。见下文。

def statistics(request):
context=RequestContext(request)

xdata = ["Apple", "Apricot", "Avocado", "Banana", "Boysenberries", "Blueberries", "Dates", "Grapefruit", "Kiwi", "Lemon"]
ydata = [52, 48, 160, 94, 75, 71, 490, 82, 46, 17]
chartdata = {'x': xdata, 'y': ydata}
charttype = "pieChart"
chartcontainer = 'piechart_container'
data = {
'charttype': charttype,
'chartdata': chartdata,
'chartcontainer': chartcontainer,
'extra': {
'x_is_date': False,
'x_axis_format': '',
'tag_script_js': True,
'jquery_on_ready': False,
'donut':True,
'donutRatio':0.35,
'chart_attr':{
'labelThreshold':0.5,
'labelType':'\"percent\"',
}
}
}
return render_to_response('App/statistics.html',data)

关于javascript - 如何用Django-nvd3绘制圆环图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30126304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com