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

NameTypeDefault
segmentslist | NoneNone
titlestr | NoneNone
widthint300
heightint300
donutboolFalse
inner_radiusfloat0.6
show_labelsboolTrue
show_legendboolTrue
custom_classstr''
**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 2033, 2034, 2035, 2036, 2445. Override those rules, or the custom properties they read, in a stylesheet loaded after it.