Wagtail Charts
Chart.js charts in Wagtail, edited and customised from the Wagtail admin
See it in action
Getting started
Assuming you have a Wagtail project up and running:
pip install wagtailcharts
Add wagtailcharts to your settings.py in the INSTALLED_APPS section, before the core wagtail packages:
INSTALLED_APPS = [
# ...
'wagtailcharts',
# ...
]
Add a wagtailcharts ChartBlock to one of your StreamFields:
from wagtailcharts.blocks import ChartBlock
class ContentBlocks(StreamBlock):
chart_block = ChartBlock()
Include your streamblock in one of your pages
class HomePage(Page):
body = StreamField(ContentBlocks())
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
Add the wagtailcharts_tags templatetag to your template and call the render_charts tag just before your </body> closing tag.
Please note that you must render your chart block so that the render_charts tag can detect the charts.
Here is a tiny example of a page rendering template:
{% load wagtailcore_tags wagtailcharts_tags %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-6">
<h1>{{self.title}}</h1>
<div class="excerpt">{{self.excerpt|richtext}}</div>
</div>
</div>
{% for block in self.body %}
{% include_block block %}
{% endfor %}
</div>
{% endblock %}
{% block extra_js %}
{% render_charts %}
{% endblock %}
Configuration
ChartBlock accepts a few extra arguments in addition to the standard StructBlock arguments.
colors
A tuple of color tuples defining the available colors in the editor.
from wagtailcharts.blocks import ChartBlock
COLORS = (
('#ff0000', 'Red'),
('#00ff00', 'Green'),
('#0000ff', 'Blue'),
)
class ContentBlocks(StreamBlock):
chart_block = ChartBlock(colors=COLORS)
chart_types
You can override the default chart types available for your ChartBlock instance:
from wagtailcharts.blocks import ChartBlock
CHART_TYPES = (
('line', 'Custom title for line chart'),
)
class ContentBlocks(StreamBlock):
chart_block = ChartBlock(chart_types=CHART_TYPES)
The default types are:
CHART_TYPES = (
('line', 'Line Chart'),
('bar', 'Vertical Bar Chart'),
('bar_horizontal', 'Horizontal Bar Chart'),
('area', 'Area Chart'),
('multi', 'Combo Line/Bar/Area Chart'),
('pie', 'Pie Chart'),
('doughnut', 'Doughnut Chart'),
('radar', 'Radar Chart'),
('polar', 'Polar Chart'),
('waterfall', 'Waterfall Chart')
)
callbacks
Since ChartJS and the plugins have a plethora of options available, we will never be able to make them all available within the wagtail interface. That is why we added a chart config callback option.
CHART_CONFIG_CALLBACKS = (
('barchart_labels', 'Bigger font and bold labels'),
)
class ContentBlocks(StreamBlock):
chart_block = ChartBlock(callbacks=CHART_CONFIG_CALLBACKS)
You then need to have a global function named the same (in this case 'barchart_labels') that returns an options object with the overrides/addons you want to add:
window.barchart_labels = function() {
return {
plugins: {
datalabels: {
font: {
size: 18,
weight: 'bold',
},
color: '#ff0000'
}
}
}
}
Localize number formatting according to a specific locale
Wagtail chart formats numbers according to the browser's default locale by default from version 0.6 onwards.
You can override this by setting a global javascript variable called WAGTAILCHARTS_LOCALE before calling the render_charts template tag:
{% load wagtailcharts_tags %}
<!-- Your content here -->
{% block extra_js %}
<script>WAGTAILCHARTS_LOCALE = 'is-IS';</script>
{% render_charts %}
{% endblock %}
Dependencies
- This project relies on Jspreadsheet Community Edition for data entry and manipulation.
- Charts are rendered using Chart.js.
- 100% stacked bar charts use a plugin https://github.com/y-takey/chartjs-plugin-stacked100
- Datalabels use a plugin [https://chartjs-plugin-datalabels.netlify.app] (https://chartjs-plugin-datalabels.netlify.app)
Release notes
For release notes, visit this link
Metadata
Release files for wagtailcharts 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wagtailcharts-0.7.tar.gz | 282.0 kB | Without provenance | Details for wagtailcharts-0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wagtailcharts-0.7-py3-none-any.whl | Python 3 | none | any | Details for wagtailcharts-0.7-py3-none-any.whl |
Total release size: 571.5 kB
Release files / wagtailcharts-0.7.tar.gz
| Download URL | wagtailcharts-0.7.tar.gz |
|---|---|
| Size | 282.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15fa93497785e968828bebe4d09d514315335d94ad5ba8e13b29ce351f141367
|
|
BLAKE2b-256 checksum How to use checksums |
d624f08e98c193a6f5dc0e4a30d2115c11ef6dfd97f71ed6d97245b3b9bff9c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / wagtailcharts-0.7-py3-none-any.whl
| Download URL | wagtailcharts-0.7-py3-none-any.whl |
|---|---|
| Size | 289.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0c10655b1a856dbdabb094f22acd890a9cea00e408ea9e154a1e4a431306b24
|
|
BLAKE2b-256 checksum How to use checksums |
14525d9a424fc7832dbc8438532aa67ded127c05e30661cf5f509a1b381f574f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for wagtailcharts 0.7
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.