Open sergeyvladimirovichmelnichenko opened 10 years ago
Try to change xdata = map(lambda x: start_time + x * 1000000000, xdata)
to xdata = list(map(lambda x: start_time + x * 1000000000, xdata))
and so on.
This confused me too for a bit when trying to get a demo line chart to work. Writing here in case it helps someone else who's equally new to all this.
The error I was getting from Django was the same 'map' object is not subscriptable
referring to line 220 in my venv's lib/python3.4/site-packages/django_nvd3/templatetags/nvd3_tags.py
but that was the symptom not the cause. As Renkai points out above the issue is a python2/3 compatibilty problem in the demo code (not in the nvd3 package), in my case xdata = map(lambda x: start_time + x * 1000000000, xdata)
in the demo_linechart
function.
Changing it and the similar line beneath to xdata = list(map(lambda x: start_time + x * 1000000000, xdata))
fixed it for me.
The "list(" should be added in several such places. Ando more: to get nvd3 working on Python 3.4.2 i changed nvd3_tags.py : unicode to str in 2 places. Is it possible to make relevant versions to download via pip for Python 2.7 and Python 3 ?
Please - help to understand :
Request Method: GET Request URL: http://189.189.2.499:8080/ITN/chart_test1/ Django Version: 1.5.1 Exception Type: TypeError Exception Value:
'map' object is not subscriptable
Exception Location: C:\Python33\lib\site-packages\nvd3\NVD3Chart.py in, line 189
Python Executable: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe
Python Version: 3.3.2
def demo_linechart(request): """ lineChart page """ start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 150 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata)
{% load nvd3_tags %}
{# Jquery CDN : Needed when using jquery_on_ready=True #} {% include_chart_jscss %} {% load_chart charttype chartdata chartcontainer extra %} {% include_container chartcontainer %}https://github.com/areski/django-nvd3/tree/master/demoproject/demoproject
I made everything - as is specified in the demontsratsionny project, but I receive the following error:
'map' object is not subscriptable
in what there can be a reason?