Line Chart

Style-agnostic SVG line chart using CSS custom properties.

python 10 params

Preview

This year: 4This year: 8This year: 6This year: 11Last year: 3Last year: 5Last year: 7Last year: 8Q1Q2Q3Q4This yearLast year
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

NameTypeDefaultDescription
serieslist | NoneNoneList of series dicts with name, data, and optional color
labelslist | NoneNoneList of x-axis labels
titlestr | NoneNoneOptional chart title
widthint400SVG width (default: 400)
heightint250SVG height (default: 250)
areaboolFalseFill area under lines (default: False)
show_dotsboolTrueShow data point dots (default: True)
show_legendboolTrueShow series legend (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.line_chartSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.