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.2.0

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.2.0
File Size Uploaded Provenance Actions
ogcio_wagtail_charts-0.2.0.tar.gz 245.8 kB Without provenance Details for ogcio_wagtail_charts-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 495.7 kB

Release files / ogcio_wagtail_charts-0.2.0.tar.gz

Download URL ogcio_wagtail_charts-0.2.0.tar.gz
Size 245.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d4d271109dbf7aebab332e33d6e0e4a2d48b863f7a223589dfd51c913cc1ed0d
BLAKE2b-256 checksum
How to use checksums
8bf116ac2cfd83ca0d7ee1e2ff3100a64de62210d278d29efd9d406a6c4f9d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

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

Download URL ogcio_wagtail_charts-0.2.0-py3-none-any.whl
Size 249.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aa659f035c6f89d64903f3577e6be97c0ec816e56b48a2de23ae91f30b292e7
BLAKE2b-256 checksum
How to use checksums
62e49b9913b2c96c74e11384c444b4a0f66663f32c55975ac0d8e3e4627883fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for ogcio-wagtail-charts 0.2.0

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.

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