• Stars
    star
    405
  • Rank 105,996 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 11 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Django Class Based Views to generate Ajax charts js parameters.

Django Chartjs

Django Chartjs lets you manage charts in your Django application.

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

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 static %}
<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 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. Update urls.py with the new urls for TemplateView and AJAX call 'line_chart_json' as in chart.html

from .views import line_chart, line_chart_json

urlpatterns = [
  '...',
  path('chart', line_chart, name='line_chart'),
  path('chartJSON', line_chart_json, name='line_chart_json'),
]

4. 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!

More Repositories

1

procrastinate

PostgreSQL-based Task Queue for Python
Python
117
star
2

django-chunkator

Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
Python
110
star
3

django-ltree-demo

A demo for storing and querying trees in Django using PostgreSQL
Python
89
star
4

mlvtools-tutorial

Tutorial for a new versioning Machine Learning pipeline
JavaScript
80
star
5

vault-cli

A configurable command-line interface tool (and python library) to interact with Hashicorp Vault
Python
79
star
6

django-mail-factory

Django Mail Manager
Python
72
star
7

django-generic-filters

Easy filters for your Django Generic ListView.
Python
51
star
8

swagman

Convert PostMan Collection Report to Swagger file
Python
49
star
9

mlvtools

Public repository for versioning machine learning data
Python
43
star
10

pylogctx

🐍 Inject extra fields to each log records
Python
25
star
11

django-docusign

Integration of DocuSign's SaaS signature platform with Django
Python
25
star
12

django-anysign

Generic online signature for Django
Python
22
star
13

django-readonly-field

Make Django model fields readonly
Python
21
star
14

django-x509

How to enable x509 authentication with your Django App
Python
21
star
15

django-formidable

On the way to glory! again!
Python
20
star
16

django-agnocomplete

A front-end agnostic toolbox for autocompletion fields
Python
19
star
17

pydocusign

Python client for DocuSign signature API
Python
18
star
18

django-aggtrigg

Automatic aggregation db triggers for django
Python
17
star
19

django-saml2-idp

Authenticate users for your Django web app against a SAML 2.0 Identity Provider.
Python
14
star
20

django-highcharts

**WARNING: UNMAINTAINED SINCE SEPT 2016** Generate charts in you Django application using Highcharts helpers
JavaScript
12
star
21

ember-cli-embedded

Control how your Ember applications boot in non-Ember pages/apps.
TypeScript
11
star
22

septentrion

Python CLI tool for managing and executing hand-written PostgreSQL migrations
Python
9
star
23

django-north

Django library for managing and executing hand-written PostgreSQL migrations
Python
9
star
24

django-sql-log

Django SQL Log
Python
8
star
25

populous

populate your database with god-like powers
Python
8
star
26

dragndoc

UI widget to split and order document pages into sub documents
JavaScript
8
star
27

django-email-change

django-email-change adds support for email address change and confirmation.
Python
8
star
28

layout-linter

lint your HTML based on your own custom rules
JavaScript
8
star
29

jenkins-yml

Define job in project as YML
Python
7
star
30

django-plainpasswordhasher

UNMAINTAINED SINCE SEP 2016 !!!!!! Was: Dummy (plain text) password hashing for Django... for use in tests!
Python
7
star
31

django-compose-settings

Django composable settings loader.
Python
6
star
32

jenkins-epo

🚦 Increase Jenkins features with GitHub integration
Python
6
star
33

ansible-role-jenkins-node

Provision a Jenkins SSH slave
5
star
34

django-pimpmytheme

load specific css or template depending on a model you define
Python
5
star
35

pg-magicplan

Improve planning of EXISTS in PostgreSQL subquery
C
5
star
36

django-adobesign

AdobeSign backend for django-anysign
Python
5
star
37

multipart-reader

Multipart/* reader extracted from awsome `aiohttp` project, cf.: http://aiohttp.readthedocs.org/en/stable/multipart.html.
Python
5
star
38

mock-services

Mock services
Python
5
star
39

lxdapi

Little library for learning http transactions with lxd
Python
4
star
40

crappyspider

Python
4
star
41

django-ticketoffice

One-shot authentication utilities for Django
Python
4
star
42

ember-simple-select

A simple select component for your Ember 2.0+ applications
JavaScript
4
star
43

ansible-role-boot

Ansible role to boot .lxc hosts in an inventory, Vagrantfile provided in novafloss/ansible-setup
4
star
44

slonik

Postgresql driver for python, in rust
Python
3
star
45

ansible-role-jenkins-api

Install jenkins-python + include ansible binding module
Python
3
star
46

OPE

One Page for Equity
HTML
3
star
47

django-json-dbindex

Describe your database index in json files into your apps
Python
3
star
48

ember-auto-import-chunks-json-generator

Ember.js addon to generate chunks.json file, based on ember-auto-import code splitting logic.
JavaScript
3
star
49

ember-feature-controls

Hot plug your features.
JavaScript
3
star
50

django-MacFly

Output sql migrations for ahead of time schema changes.
Python
3
star
51

django-templates-forest

Django commands to help you inspect your templates' structure
Python
3
star
52

bag8

Cli to orchestrate docker images and containers the easy way.
Python
3
star
53

python-pussycache

Cache Backend system for python objects
Python
3
star
54

django-saml2-sp

UNMAINTAINED SINCE SEPT. 30 2016 Authenticate users for your Django web app against a SAML 2.0 Identity Provider.
Python
3
star
55

ember-metrics-pendo

Ember-metrics-pendo allows to configure the Pendo service in your ember project using ember-metrics.
JavaScript
2
star
56

rate-limit-scheduler

Consume APIs with respect to their rate limits
TypeScript
2
star
57

jenkins-formula

Salt formula for jenkins master-slave installation
Python
2
star
58

ansible-ssh-agent

Role to ensure an SSH agent is ready
2
star
59

django-esutils

Django ES Utils
Python
2
star
60

django-i18nurl

Django i18n url lets you manage your multilingual url using Django.
Python
2
star
61

retry-formula

Poutre your netwerk
Python
2
star
62

check_po

Check if the po is fully translated without any fuzzy in it
Python
2
star
63

insight-installer

Chef cookbooks to run the provisionning of your insight-reloaded server.
Ruby
2
star
64

saltpad

A gui and cli to manage saltstack deployments
JavaScript
1
star
65

github-repo-control

Easily configure your Github repositories in command-line
JavaScript
1
star
66

people-slides

BBL slides
CSS
1
star
67

novapost.cookbot

Contextual execution manager
Python
1
star
68

ember-web-component-container

Wraps your Ember Application into a CustomElement for better portability
JavaScript
1
star
69

insight

**DEPRECTATED** API REST to asynchronously generate document thumbnails
Python
1
star
70

perfo

CI Performance analysis tool
JavaScript
1
star
71

django-navigator

Let you navigate between object DetailView from a ListView or a SearchView.
Python
1
star
72

eslint-config-peopledoc

ESLint config for PeopleDoc frontend projects
JavaScript
1
star
73

django-postgres-hot-upgrade

Django app that resets django.contrib.postgres caches that store postgres extensions OIDs
Python
1
star
74

broccoli-styledown

Broccoli plugin for creating styledown html from css markup
JavaScript
1
star
75

connemara

PostgreSQL replication tool to merge multiple database in a single one
Python
1
star
76

ansible-role-oracle-java

Install oracle java
Python
1
star
77

insight-reloaded

**DEPRECTATED** A full async docsplit previewer server based on Tornado and Redis
Python
1
star
78

ansible-boot-lxd

Ansible role to boot LXD containers
1
star
79

novabeacon

PUBSUB interface for beacon plug on ARDUINOS
Python
1
star
80

pg_schema_north

PostgreSQL schema deployΓΉent tool for DDL and DML
PLpgSQL
1
star
81

ember-reading-time

Medium-like reading time estimation for EmberJS.
JavaScript
1
star