django-nvd3
django-nvd3 copied to clipboard
NVD3 not displaying the graph
Hi All, While using NVD3 and the examples available on this page I am not able to generate the graph, Nothng is generated. I am using Django 2.0, Python 3.6.3 and NVD3
Here is my view.py
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)
tooltip_date = "%d %b %Y %H:%M:%S %p"
extra_serie1 = {
"tooltip": {"y_start": "", "y_end": " cal"},
"date_format": tooltip_date,
}
extra_serie2 = {
"tooltip": {"y_start": "", "y_end": " cal"},
"date_format": tooltip_date,
}
chartdata = {'x': xdata,
'name1': 'series 1', 'y1': ydata, 'extra1': extra_serie1, 'kwargs1': { 'color': '#a4c639' },
'name2': 'series 2', 'y2': ydata2, 'extra2': extra_serie2, 'kwargs2': { 'color': '#ff8af8' },
}
charttype = "lineChart"
chartcontainer = 'linechart_container' # container name
data = {
'charttype': charttype,
'chartdata': chartdata,
'extra': {'x_is_date': True,
'x_axis_format': "%d %b %Y %H",
'tag_script_js': True,
'jquery_on_ready': False,
},
}
return render(request, 'personal/linechart.html', data)
Below is the HTML
{% load nvd3_tags %}
Pls suggest what to do as nothing is displayed on the webpage
I know it's old question, but maybe it will be useful for somebody else. Wrap the maps in list. Like that: xdata = list(map(lambda x: start_time + x * 1000000000, xdata))
Do it both for xdata and ydata2. In my case it works.