Skip to main content

wagtail-charts

A chart StreamField block for Wagtail, drawn with Chart.js. Editors enter chart data in a spreadsheet editor in the Wagtail admin and choose the chart type and display settings alongside it.

Maintained by the Office of the Government Chief Information Officer (OGCIO) for gov.ie. It started as a fork of wagtailcharts by Overcast Software.

Chart types

Line, vertical bar, horizontal bar, area, combo (line/bar/area), pie, doughnut, radar, polar, waterfall and scatter. Bar and area charts can be stacked or stacked to 100%, and horizontal bars can be drawn as a pyramid.

Requirements

Installation

pip install ogcio-wagtail-charts

Add the app and its dependency to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "wagtail_charts",
    "wagtail_color_panel",
    # ...
]

Usage

Add ChartBlock to a StreamField:

from wagtail.fields import StreamField
from wagtail.models import Page

from wagtail_charts.blocks import ChartBlock


class ReportPage(Page):
    body = StreamField([
        ("chart", ChartBlock()),
    ])

Load the Chart.js scripts once in your base template, after the page content (for example just before </body>):

{% load wagtailcharts_tags %}

{% render_charts %}

Colours

Dataset colours are chosen from a palette. Pass your own as colors, a sequence of (hex value, label) pairs:

from wagtail_charts.blocks import CHART_COLOR_CHOICES, ChartBlock

ChartBlock(colors=CHART_COLOR_CHOICES + (("#ffd700", "Gold"),))

Config callbacks

To customise Chart.js options beyond the editor settings, pass named callbacks as callbacks, a sequence of (name, label) pairs. Editors can then pick one per chart:

ChartBlock(callbacks=(("hide_gridlines", "Hide gridlines"),))

Register a function with the same name before {% render_charts %}. It must return an options object, which is deep-merged into the chart's Chart.js options:

<script>
  window.WAGTAILCHARTS_CALLBACKS = {
    hide_gridlines: () => ({ scales: { x: { grid: { display: false } }, y: { grid: { display: false } } } }),
  };
</script>

Callbacks are looked up by name and never evaluated as code, so charts work under a Content Security Policy without 'unsafe-eval'.

Templates

To change the chart markup, override wagtailcharts/blocks/chart_block.html in your project's templates.

Development

python -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

Contributing

Please commit with your GitHub noreply email address (how to set it up) so that your personal address is not published in the git history.

To report a security issue, see SECURITY.md.

Releasing

  1. Update version in pyproject.toml and add an entry to CHANGELOG.md.
  2. Optionally, run the Publish workflow manually from the Actions tab to upload to TestPyPI and check the result.
  3. Create a GitHub release with a tag matching the version (for example v0.1.0). Publishing the release runs the tests, builds the package and uploads it to PyPI.

Licence

MIT. See LICENSE, which also lists the bundled third-party JavaScript libraries.

Metadata

Release files for ogcio-wagtail-charts 0.1.1

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

Source distribution (sdist)

Source distribution for ogcio-wagtail-charts 0.1.1
File Size Uploaded Provenance Actions
ogcio_wagtail_charts-0.1.1.tar.gz 244.9 kB Without provenance Details for ogcio_wagtail_charts-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ogcio-wagtail-charts 0.1.1
File Interpreter ABI Platform Actions
ogcio_wagtail_charts-0.1.1-py3-none-any.whl Python 3 none any Details for ogcio_wagtail_charts-0.1.1-py3-none-any.whl

Total release size: 494.2 kB

Release files / ogcio_wagtail_charts-0.1.1.tar.gz

Download URL ogcio_wagtail_charts-0.1.1.tar.gz
Size 244.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9603ac72885558f69af0832b29dc3f64dbe0580b9ce01affc629048bd0226d13
BLAKE2b-256 checksum
How to use checksums
56711ae760eb8fe93546c59a4f5857022200f2a59c7314f38fd1545d3a7e8f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / ogcio_wagtail_charts-0.1.1-py3-none-any.whl

Download URL ogcio_wagtail_charts-0.1.1-py3-none-any.whl
Size 249.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0069f7117a017d60f14606a4d74b3735fb0cd86bba039b18c2c1dde8a65da77
BLAKE2b-256 checksum
How to use checksums
0231ee92ecb08afbdf2bcc1b24fbd4db89bd567d1ca5ec3aa124c3385f9175e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for ogcio-wagtail-charts 0.1.1

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.1.1 This release

2 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