Pie Chart
Style-agnostic SVG pie/donut chart using CSS custom properties.
Preview
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
| Name | Type | Default | Description |
|---|---|---|---|
| segments | list | None | None | List of segment dicts with label, value, and optional color |
| title | str | None | None | Optional chart title |
| width | int | 300 | SVG width (default: 300) |
| height | int | 300 | SVG height (default: 300) |
| donut | bool | False | Render as donut chart (default: False) |
| inner_radius | float | 0.6 | Inner radius ratio for donut (0-1, default: 0.6) |
| show_labels | bool | True | Show percentage labels (default: True) |
| show_legend | bool | True | Show legend below chart (default: True) |
| custom_class | str | '' | 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
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.pie_chart | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 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. |