Skip to main content

Django NVD3

Project description

Description:

Django-nvd3 is a wrapper for NVD3 graph library

nvd3:

NVD3 http://nvd3.org/

d3:

Data-Driven Documents http://d3js.org/

NVD3 is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you.

https://www.travis-ci.org/areski/django-nvd3.png?branch=master

endorse

Installation

Install, upgrade and uninstall django-nvd3 with these commands:

$ pip install django-nvd3
$ pip install --upgrade django-nvd3
$ pip uninstall django-nvd3

Then edit settings.py from your django project and add ‘django_nvd3’ in your ‘INSTALLED_APPS’ setting.

Dependencies

Django-nvd3 have one major dependencie:

Bower will be used to install D3 and NvD3, see bower website for futher info : http://bower.io/

Bower depends on Node and npm. It’s installed globally using npm:

npm install -g bower

To easy the integration with Django we will advice you to use django-bower.

For instance to run our demo project, you will install the dependencies from requirements.txt and then install django-bower. Django-bower is not a mandatory dependencies as the user should be free to install JS files using different method.

To install django-bower:

$ pip install django-bower

Read the documentation about Django-bower to find out how to configure it properly for your project: https://github.com/nvbn/django-bower

Then in the demo project directory just type the following:

$ python manage.py bower_install
$ python manage.py collectstatic

This will create a directory “components” where d3 & nvd3 will be installed.

You can see example settings file in demoproject.

Example how to create a pieChart

Let’s say we have a simple view in which we want to display the amount of calories per fruit.

So to achieve this, we will edit our view.py, we will prepare the data that will be displayed:

xdata = ["Apple", "Apricot", "Avocado", "Banana", "Boysenberries", "Blueberries", "Dates", "Grapefruit", "Kiwi", "Lemon"]
ydata = [52, 48, 160, 94, 75, 71, 490, 82, 46, 17]
chartdata = {'x': xdata, 'y': ydata}
charttype = "pieChart"
data = {
    'charttype': charttype,
    'chartdata': chartdata
}
return render_to_response('piechart.html', data)

We will render the template ‘piechart.html’ with a dictionary ‘data’ which contains ‘charttype’ and ‘chartdata’.

Our template piechart.html could look like this:

{% load static %}
<link media="all" href="{% static 'nvd3/src/nv.d3.css' %}" type="text/css" rel="stylesheet" />
<script type="text/javascript" src='{% static 'd3/d3.min.js' %}'></script>
<script type="text/javascript" src='{% static 'nvd3/nv.d3.min.js' %}'></script>

{% load nvd3_tags %}
<head>
    {% load_chart charttype chartdata "piechart_container" %}
</head>
<body>
    <h1>Fruits vs Calories</h1>
    {% include_container "piechart_container" 400 600 %}
</body>

We use include the Javascript and CSS code for D3/NVD3. We start preparing and display the javascript code needed to render our pieChart:

{% load_chart charttype chartdata "piechart_container" %}

Finally we created a div container which will be used to display the chart.

The result will be a beautiful and interactive chart:

https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/piechart_fruits_vs_calories.png

For more examples, please look at the demoproject directory in our repository, it shows an simple example for all the supported charts by django-nvd3.

Live demo of NVD3

See a live demo on jsfiddle : http://jsfiddle.net/areski/z4zuH/3/

Supported nvd3 charts

Charts list:

https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/lineWithFocusChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/lineChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/multiBarChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/pieChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/stackedAreaChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/multiBarHorizontalChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/linePlusBarChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/cumulativeLineChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/discreteBarChart.png https://raw.github.com/areski/django-nvd3/master/docs/source/_static/screenshot/scatterChart.png

Projects using Django-nvd3

  • CDR-Stats : www.cdr-stats.org

  • Newfies-Dialer : www.newfies-dialer.org

Documentation

Documentation is available on ‘Read the Docs’: http://django-nvd3.readthedocs.org

Changelog

Changelog summary : https://github.com/areski/django-nvd3/blob/master/CHANGELOG.rst

License

Django-nvd3 is licensed under MIT, see MIT-LICENSE.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-nvd3-0.3.1.tar.gz (18.2 kB view details)

Uploaded Source

File details

Details for the file django-nvd3-0.3.1.tar.gz.

File metadata

  • Download URL: django-nvd3-0.3.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-nvd3-0.3.1.tar.gz
Algorithm Hash digest
SHA256 acbd1c5122bfabb8929a4125ebb29aa609201e83a8c7d37e1d972afbd36b85b4
MD5 6ecf5e78096a22253f10b77aa7ca9710
BLAKE2b-256 734c2433542d923110d8d909a8c06496615ca7174ad2f853feea637f6f0c0df3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page