Skip to main content

Django Chartjs lets you manage charts in your Django application.

https://travis-ci.org/peopledoc/django-chartjs.svg?branch=master https://coveralls.io/repos/novapost/django-chartjs/badge.png?branch=master&style=flat https://img.shields.io/pypi/v/django-chartjs.svg

This is compatible with Chart.js and Highcharts JS libraries.

Using a set of predefined Class Based Views you are able to get started after writing just your SQL query.

Getting Started

Install django-chartjs:

pip install django-chartjs

Add it to your INSTALLED_APPS settings:

INSTALLED_APPS = (
    '...',
    'chartjs',
)

Using it

A simple Line Chart example.

1. Create the HTML file

{% load staticfiles %}
<html>
    <head>
        <title>django-chartjs line chart demo</title>
        <!--[if lte IE 8]>
            <script src="{% static 'js/excanvas.js' %}"></script>
        <![endif]-->
    </head>
    <body>
        <h1>Some Line Charts loaded in Ajax!</h1>

        <canvas id="myChart" width="500" height="400"></canvas>

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
        <script type="text/javascript" src="{% static 'js/Chart.min.js' %}"></script>
        <script type="text/javascript">
            $.get('{% url "line_chart_json" %}', function(data) {
                var ctx = $("#myChart").get(0).getContext("2d");
                new Chart(ctx, {
                    type: 'line', data: data
                });
            });
        </script>
    </body>
</html>

2. Create the view with labels and data definition

from random import randint
from django.views.generic import TemplateView
from chartjs.views.lines import BaseLineChartView


class LineChartJSONView(BaseLineChartView):
    def get_labels(self):
        """Return 7 labels for the x-axis."""
        return ["January", "February", "March", "April", "May", "June", "July"]

    def get_providers(self):
        """Return names of datasets."""
        return ["Central", "Eastside", "Westside"]

    def get_data(self):
        """Return 3 datasets to plot."""

        return [[75, 44, 92, 11, 44, 95, 35],
                [41, 92, 18, 3, 73, 87, 92],
                [87, 21, 94, 3, 90, 13, 65]]


line_chart = TemplateView.as_view(template_name='line_chart.html')
line_chart_json = LineChartJSONView.as_view()

3. Get a Chart.js Line Chart

https://raw.github.com/peopledoc/django-chartjs/master/docs/_static/django-chartjs.png

It is that simple!

For other examples including a HighCharts line chart, don’t hesitate to look at the demo project.

Also, feel free to contribute your demo!

Release files for django-chartjs 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-chartjs 1.4.0
File Size Uploaded
django-chartjs-1.4.0.tar.gz 568.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-chartjs 1.4.0
File Interpreter ABI Platform
django_chartjs-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / django-chartjs-1.4.0.tar.gz

Download URL django-chartjs-1.4.0.tar.gz
Size 568.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f521be3b4b413549991240caab41d925971cc32c0df80b7c50907d08b2ff21d4
BLAKE2b-256 checksum
How to use checksums
bce491560842d4f157dba4c6f43b333c503d33c7f129a2df4d15b927a64543ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.7

Release files / django_chartjs-1.4.0-py3-none-any.whl

Download URL django_chartjs-1.4.0-py3-none-any.whl
Size 598.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9747a2ef6a0aabfbd5b3d52f0827af761eb764ed3707934aa5cb7269cc08940e
BLAKE2b-256 checksum
How to use checksums
b4773889cd99408cd51befd0e69c3d3ee96bb81715b3149e9d2749aaca664992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.7

Release history Release notifications | RSS feed

2.3.0

2 release files

2.2.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.5.0

2 release files

This release

1.4.0 This release

2 release files

1.3

2 release files

1.2

2 release files

1.1

1 release file

1.0

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page