Skip to main content

Chart.js charts for Wagtail

Project description

Wagtail Charts

Chart.js charts in Wagtail, edited and customised from the Wagtail admin

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')
)

Dependencies

Release notes

Version 0.3.3

  • Fixed a regression from release 0.3.3 when using multiple charts on same page.

Version 0.3.2

  • Added support for external HTML legend
  • Fixed bug in doughnut chart

Version 0.3.1

  • Added options for border width and border color for pie charts
  • Added support for Wagtail 5
  • Removed support for Wagtail <3

Version 0.3

  • Added Waterfall Chart
  • Added DataLabels
  • Added options for:
    • grid display
    • axis display
    • y tick precision
    • datalabel and tooltip precision
  • Added grouping of options into multiple collapsible panels with buttons
  • Multiple bugfixes

Version 0.2

  • Added support for Wagtail 3.0

Version 0.1

  • Initial release

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

wagtailcharts-0.4.0.tar.gz (282.0 kB view details)

Uploaded Source

Built Distribution

wagtailcharts-0.4.0-py3-none-any.whl (289.8 kB view details)

Uploaded Python 3

File details

Details for the file wagtailcharts-0.4.0.tar.gz.

File metadata

  • Download URL: wagtailcharts-0.4.0.tar.gz
  • Upload date:
  • Size: 282.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.15

File hashes

Hashes for wagtailcharts-0.4.0.tar.gz
Algorithm Hash digest
SHA256 da2d579cfe48f7424d327e046ab678645a3863736b5758dbb2d28f56b0859b39
MD5 cd715181820784480fe9582418f06b85
BLAKE2b-256 40212d63e679115601047bc28c06c1b27b20cd2d7470dd0b5194fd508ba996ed

See more details on using hashes here.

File details

Details for the file wagtailcharts-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtailcharts-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccd4f03dbc275c0f040403372d2de80146e43ed7f5e57b44bfefa210228a0c88
MD5 9cbc73d3bd31587ae0afbec879c6e971
BLAKE2b-256 06af2c9b1367d23185d1a94beb38d56c555bad294fd4009ef9e223ce53f8a0ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page