Pie Chart

Style-agnostic SVG pie/donut chart using CSS custom properties.

python 10 params

Preview

Traffic sourcesDirect: 45 (45.0%)45%Search: 35 (35.0%)35%Referral: 20 (20.0%)20%DirectSearchReferral
Arguments
pie_chart(segments=[{'label': 'Direct', 'value': 45}, {'label': 'Search', 'value': 35}, {'label': 'Referral', 'value': 20}], title='Traffic sources')

Usage

views.py
python
from djust import LiveView
from djust.components import PieChart


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = PieChart(segments=[{'label': 'Direct', 'value': 45}, {'label': 'Search', 'value': 35}, {'label': 'Referral', 'value': 20}], title='Traffic sources')
my_template.html
django
{{ component }}

Parameters

NameTypeDefaultDescription
segmentslist | NoneNoneList of segment dicts with label, value, and optional color
titlestr | NoneNoneOptional chart title
widthint300SVG width (default: 300)
heightint300SVG height (default: 300)
donutboolFalseRender as donut chart (default: False)
inner_radiusfloat0.6Inner radius ratio for donut (0-1, default: 0.6)
show_labelsboolTrueShow percentage labels (default: True)
show_legendboolTrueShow legend below chart (default: True)
custom_classstr''Additional CSS classes
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.pie_chartSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 5 of this component's classes at line 2087, 2088, 2089, 2090, 2548. Override those rules, or the custom properties they read, in a stylesheet loaded after it.