Line Chart
Style-agnostic SVG line chart using CSS custom properties.
Preview
Arguments
line_chart(series=[{'name': 'This year', 'data': [4, 8, 6, 11]}, {'name': 'Last year', 'data': [3, 5, 7, 8]}], labels=['Q1', 'Q2', 'Q3', 'Q4'])Usage
views.py
python
from djust import LiveView
from djust.components import LineChart
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = LineChart(series=[{'name': 'This year', 'data': [4, 8, 6, 11]}, {'name': 'Last year', 'data': [3, 5, 7, 8]}], labels=['Q1', 'Q2', 'Q3', 'Q4'])my_template.html
django
{{ component }}Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| series | list | None | None | List of series dicts with name, data, and optional color |
| labels | list | None | None | List of x-axis labels |
| title | str | None | None | Optional chart title |
| width | int | 400 | SVG width (default: 400) |
| height | int | 250 | SVG height (default: 250) |
| area | bool | False | Fill area under lines (default: False) |
| show_dots | bool | True | Show data point dots (default: True) |
| show_legend | bool | True | Show series legend (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.line_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 2078, 2079, 2081, 2082, 2084. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |