Django integration

The package includes a Django app to help integrating nvd3_py in Django.

Quick start

  1. Add “django_nvd3” to your INSTALLED_APPS settings like this:
INSTALLED_APPS = [
   ...
   "django_nvd3",
]
  1. Load the tags in your template:
{% load nvd3_tags %}
  1. Use it.

Reference

django_nvd3.templatetags.nvd3_tags.nvd3_static(use_cdnjs=False)

Load the required JavaScript and CSS files.

Usage:

<html>
<head>
    ...
    {# serve the static files yourself... #}
    {% nvd3_static %}
    {# ...or use cdnjs #}
    {% nvd3_static use_cdnjs=True %}
    ...
</head>
<body>
    ...
django_nvd3.templatetags.nvd3_tags.nvd3_static_data(chart, data, width=500, height=400)

Include the chart in the page with the given data.

Parameters:
  • chart (nvd3.Chart) – The chart to render.
  • data – the data to pass to the chart.
  • width – SVG tag width.
  • height – SVG tag height.

Usage:

{% nvd3_static_data chart data 400 300 %}
django_nvd3.templatetags.nvd3_tags.nvd3_remote_json(chart, url, width=400, height=500)

Include the chart in the page loading the data from a server.

Parameters:
  • chart (nvd3.Chart) – The chart to render.
  • url (str) – the url where to retrieve the data.
  • width – SVG tag width.
  • height – SVG tag height.

Usage:

{% nvd3_remote_json chart url 400 300 %}