A thin wrapper around Google Chart API that tries not to invent a new language for describing charts.
Project description
django-chart-tools is a simple app for creating charts in django templates using Google Chart API. It doesn’t try to invent another language for defining charts unlike other Google Chart API wrappers. It instead make it easy to leverage the power of existing user-friendly chart-building tools like http://imagecharteditor.appspot.com/ or http://dexautomation.com/googlechartgenerator.php
Installation
$ pip install django-chart-tools
or
$ easy_install django-chart-tools
or grab the latest and the greatest version from bitbucket (http://bitbucket.org/kmike/django-chart-tools)
Then add ‘chart_tools’ to your INSTALLED_APPS.
Usage
Generate a chart you like using http://imagecharteditor.appspot.com/ .
Copy&paste output to your template and wrap it with {% chart %} … {% endchart %} tags:
{% load chart_tags %} {% chart %} http://chart.apis.google.com/chart ?chxr=0,0,160 &chxt=y &chbh=a &chs=440x220 &cht=bvs &chco=4D89F9 &chds=0,160 &chd=t:10,50,60,80,40,60,30 &chtt=Horizontal+bar+chart {% endchart %}
You’ll get the <img/> tag with generated chart in you template after rendering.
chart tag also allows cleaned-up version of the example above:
{% load chart_tags %} {% chart %} chxr=0,0,160 chxt=y chbh=a chs=440x220 cht=bvs chco=4D89F9 chds=0,160 chd=t:10,50,60,80,40,60,30 chtt=Horizontal+bar+chart {% endchart %}
Replace test data with your real data. For example, we want to provide real values. Change the test data in Image Chart Editor. The parameter we change will be highlited. It is ‘chd’ in our case. So now we replace ‘chd’ data with real data that comes from view:
{% load chart_tags %} {% chart %} chxr=0,0,160 chxt=y chbh=a chs=440x220 cht=bvs chco=4D89F9 chds=0,160 chd=t:{{ values|join:',' }} chtt=Horizontal+bar+chart {% endchart %}
That’s all.
There is also up-to-date API reference from Google: http://code.google.com/intl/en/apis/chart/docs/chart_params.html
What is {% chart %} tag for
I found plain copy-pasted <img> html tag with some {{ variables }} unmaintainable and unreadable so the {% chart %} was introduced.
It removes all whitespaces;
builds chart url from parameter list;
generates the <img> tag with proper ‘src’, ‘width’ and ‘height’ attributes
so generated charts can be nicely formatted and it is possible to maintain them later.
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
File details
Details for the file django-chart-tools-0.1.1.tar.gz
.
File metadata
- Download URL: django-chart-tools-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a748c594d968d7335a096e26efaf109eb218b8a8b9d8f1ee3a186de30316227 |
|
MD5 | ce845bedbafffb24a8ea09a05f04967d |
|
BLAKE2b-256 | b70f3e61c74b9852a31dcc073d5a136aa53eab7c3cbd21c439caf5815e647a0d |