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 |
|---|---|---|
| segments | list | None | None |
| title | str | None | None |
| width | int | 300 |
| height | int | 300 |
| donut | bool | False |
| inner_radius | float | 0.6 |
| show_labels | bool | True |
| show_legend | bool | True |
| custom_class | str | '' |
| **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 2033, 2034, 2035, 2036, 2445. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |