Skip to main content
##################
Django-Highchartit
##################

.. image:: https://readthedocs.org/projects/django-chartit2/badge/?version=latest
:target: http://django-chartit2.readthedocs.org/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://travis-ci.org/grantmcconnaughey/django-chartit2.svg?branch=master
:target: https://travis-ci.org/grantmcconnaughey/django-chartit2

.. image:: https://coveralls.io/repos/grantmcconnaughey/django-chartit2/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/grantmcconnaughey/django-chartit2?branch=master


The fork of Django Charit2 and merge Django Chartit new feature that adds support for Python 3 and Django 1.8+!

Django Chartit is a Django app that can be used to easily create charts from the data
in your database. The charts are rendered using ``Highcharts`` and ``jQuery``
JavaScript libraries. Data in your database can be plotted as simple line
charts, column charts, area charts, scatter plots, and many more chart types.
Data can also be plotted as Pivot Charts where the data is grouped and/or
pivoted by specific column(s).

========
Features
========

- Plot charts from models.
- Plot data from multiple models on the same axis on a chart.
- Plot pivot charts from models. Data can be pivoted by across multiple
columns.
- Legend pivot charts by multiple columns.
- Combine data from multiple models to plot on same pivot charts.
- Plot a pareto chart, paretoed by a specific column.
- Plot only a top few items per category in a pivot chart.

=============================================
Improvements from the original Django-Chartit2
=============================================

- Added Python 3 compatibility
- Added Django 1.8 and 1.9 compatibility
- Added documentation to ReadTheDocs
- Added automated testing via Travis CI
- Added test coverage tracking via Coveralls
- Added annotate support from Django-Chartit

============
Installation
============

You can install Django-Highcharts from PyPI. Just do ::

$ pip install django-highchartit

You also need supporting JavaScript libraries. See the
`Required JavaScript Libraries`_ section for more details.

==========
How to Use
==========

Plotting a chart or pivot chart on a webpage involves the following steps.

1. Create a ``DataPool`` or ``PivotDataPool`` object that specifies what data
you need to retrieve and from where.
2. Create a ``Chart`` or ``PivotChart`` object to plot the data in the
``DataPool`` or ``PivotDataPool`` respectively.
3. Return the ``Chart``/``PivotChart`` object from a django ``view`` function
to the django template.
4. Use the ``load_charts`` template tag to load the charts to HTML tags with
specific `ids`.

It is easier to explain the steps above with examples. So read on.

====================
How to Create Charts
====================
Here is a short example of how to create a line chart. Let's say we have a
simple model with 3 fields - one for month and two for temperatures of Boston
and Houston. ::

class MonthlyWeatherByCity(models.Model):
month = models.IntegerField()
boston_temp = models.DecimalField(max_digits=5, decimal_places=1)
houston_temp = models.DecimalField(max_digits=5, decimal_places=1)

And let's say we want to create a simple line chart of month on the x-axis
and the temperatures of the two cities on the y-axis. ::

from chartit import DataPool, Chart

def weather_chart_view(request):
#Step 1: Create a DataPool with the data we want to retrieve.
weatherdata = \
DataPool(
series=
[{'options': {
'source': MonthlyWeatherByCity.objects.all()},
'terms': [
'month',
'houston_temp',
'boston_temp']}
])

#Step 2: Create the Chart object
cht = Chart(
datasource = weatherdata,
series_options =
[{'options':{
'type': 'line',
'stacking': False},
'terms':{
'month': [
'boston_temp',
'houston_temp']
}}],
chart_options =
{'title': {
'text': 'Weather Data of Boston and Houston'},
'xAxis': {
'title': {
'text': 'Month number'}}})

#Step 3: Send the chart object to the template.
return render_to_response({'weatherchart': cht})

And you can use the ``load_charts`` filter in the django template to render
the chart. ::

<head>
<!-- code to include the highcharts and jQuery libraries goes here -->
<!-- load_charts filter takes a comma-separated list of id's where -->
<!-- the charts need to be rendered to -->
{% load chartit %}
{{ weatherchart|load_charts:"container" }}
</head>
<body>
<div id='container'> Chart will be rendered here </div>
</body>

===========================
How to Create Pivot Charts
===========================

Here is an example of how to create a pivot chart. Let's say we have the
following model. ::

class DailyWeather(models.Model):
month = models.IntegerField()
day = models.IntegerField()
temperature = models.DecimalField(max_digits=5, decimal_places=1)
rainfall = models.DecimalField(max_digits=5, decimal_places=1)
city = models.CharField(max_length=50)
state = models.CharField(max_length=2)

We want to plot a pivot chart of month (along the x-axis) versus the average
rainfall (along the y-axis) of the top 3 cities with highest average
rainfall in each month. ::

from chartit import PivotDataPool, PivotChart

def rainfall_pivot_chart_view(request):
#Step 1: Create a PivotDataPool with the data we want to retrieve.
rainpivotdata = \
PivotDataPool(
series =
[{'options': {
'source': DailyWeather.objects.all(),
'categories': ['month']},
'terms': {
'avg_rain': Avg('rainfall'),
'legend_by': ['city'],
'top_n_per_cat': 3}}
])

#Step 2: Create the PivotChart object
rainpivcht = \
PivotChart(
datasource = rainpivotdata,
series_options =
[{'options':{
'type': 'column',
'stacking': True},
'terms':[
'avg_rain']}],
chart_options =
{'title': {
'text': 'Rain by Month in top 3 cities'},
'xAxis': {
'title': {
'text': 'Month'}}})

#Step 3: Send the PivotChart object to the template.
return render_to_response({'rainpivchart': rainpivcht})

And you can use the ``load_charts`` filter in the django template to render
the chart. ::

<head>
<!-- code to include the highcharts and jQuery libraries goes here -->
<!-- load_charts filter takes a comma-separated list of id's where -->
<!-- the charts need to be rendered to -->
{% load chartit %}
{{ rainpivchart|load_charts:"container" }}
</head>
<body>
<div id='container'> Chart will be rendered here </div>
</body>

====
Rendering multiple charts
====

It is possible to render multiple charts in the same template. The first
argument to ``load_charts`` is the Chart object or a list of Chart objects,
and the second is a comma separated list of HTML IDs where the charts will
be rendered.

When calling Django's ``render`` you have to pass all you charts as a list::

return render(request, 'index.html',
{
'chart_list' : [chart_1, chart_2],
}
)

Then in your template you have to use the proper syntax::

<head>
{% load chartit %}
{{ chart_list|load_charts:"chart_1,chart_2" }}
</head>
<body>
<div id="chart_1">First chart will be rendered here</div>
<div id="chart_2">Second chart will be rendered here</div>
</body>

====
Demo
====

The above examples are just a brief taste of what you can do with
Django-Chartit. For more examples and to look at the charts in actions, check
out the `demo website <http://chartit.shutupandship.com/demo>`_.

===============
Documentation
===============

Full documentation is available
`here <http://chartit.shutupandship.com/docs>`_ .

=============================
Required JavaScript Libraries
=============================

The following JavaScript Libraries are required for using Django-Highcharts.

- `jQuery <http://jquery.com>`_
- `Highcharts <http://highcharts.com>`_

.. note:: While ``Django-Chartit`` and ``Django-Chartit 2`` itself is licensed under the BSD license,
``Highcharts`` is licensed under the `Highcharts license
<http://www.highcharts.com/license>`_ and ``jQuery`` is licensed under both
MIT License and GNU General Public License (GPL) Version 2. It is your own
responsibility to abide by respective licenses when downloading and using
the supporting JavaScript libraries.

Metadata

Release files for django-highchartit 0.2.3

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

Source distributions (sdists)

Source distribution for django-highchartit 0.2.3
File Size Uploaded Provenance Actions
django-highchartit-0.2.3.zip 33.4 kB Without provenance Details for django-highchartit-0.2.3.zip
django-highchartit-0.2.3.win32.zip 48.9 kB Without provenance Details for django-highchartit-0.2.3.win32.zip

Built distribution (wheel)

Table of built distributions (wheels) for django-highchartit 0.2.3
File Interpreter ABI Platform Actions
django_highchartit-0.2.3-py2.7.egg Legacy Egg format - - Details for django_highchartit-0.2.3-py2.7.egg

Total release size: 129.3 kB

Release files / django-highchartit-0.2.3.zip

Download URL django-highchartit-0.2.3.zip
Size 33.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6e7ea209b11d60bf6f7d461732377b353e2109b325367eab329ccb167fa9d382
BLAKE2b-256 checksum
How to use checksums
311512de436183b9b0e508ea7be0d1d2baf5b1230d2030f24c8dc26df67be7a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-highchartit-0.2.3.win32.zip

Download URL django-highchartit-0.2.3.win32.zip
Size 48.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e4615e92c55729783c7dec3d809543eb2a43966c0f2c7a5c8b69ea001668cbc5
BLAKE2b-256 checksum
How to use checksums
f80c18d1cd826668ccd80799e714ba2e63e38fc8f3fab691da2e874919aa8612
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_highchartit-0.2.3-py2.7.egg

Download URL django_highchartit-0.2.3-py2.7.egg
Size 47.0 kB
Tags Egg
SHA-256 checksum
How to use checksums
8e0ed9f6f4145de77c9c8d5ded95e1a7ec436512b498a8f3ff95b66e44ffdda7
BLAKE2b-256 checksum
How to use checksums
3d2ba9b388ad173bce40fc4bdb1a1e90d463e3031c6349e3366b41a12eff1662
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-highchartit 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.3 This release

3 release files No provenance

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