Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVD3 not displaying the graph #99

Open
sachinjakhar23 opened this issue May 10, 2018 · 1 comment
Open

NVD3 not displaying the graph #99

sachinjakhar23 opened this issue May 10, 2018 · 1 comment

Comments

@sachinjakhar23
Copy link

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

<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.min.js"></script> <script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.min.js"></script>

{% load nvd3_tags %}

<script>{% load_chart charttype chartdata "linechart_container" extra %}</script> <script>{% include_container "linechart_container" 400 600 %}</script>

Pls suggest what to do as nothing is displayed on the webpage

@mikuslaw
Copy link

mikuslaw commented Oct 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants