【发布时间】:2017-05-29 15:58:05
【问题描述】:
我正在使用 django-nvd3 显示多条形图。我得到的数据几乎就像示例中一样。 http://django-nvd3.readthedocs.io/en/latest/classes-doc/multi-bar-chart.html
view.py
...
return render_to_response('multibarchart.html', {'data': data, 'form': form})
我的数据是一本包含 nvd3 的所有信息的字典。数据来自数据库。字典中有几年的数据,我想访问这些数据以对应选择表单的选择。
data = {2014: {
'charttype': charttype,
'chartdata': chartdata},
2015: {
'charttype': charttype,
'chartdata': chartdata}
}
在 html 中,我有一个变量,其中包含所选年份的帖子,我想更改年份 nvd3 标记(此处为 2014)。
{% include_container data.dict.**2014**.chart... 400 600 %}
我尝试了几种方法,例如 ... {% with year as selected_year }}
{% include_container data.dict.{{ selected_year }}.chart... 400 600 %}
或
{% include_container data.dict.selected_year.chart... 400 600 %}
但我无法弄清楚这一年是如何动态的。谢谢
【问题讨论】:
标签: python django variables tags nvd3.js