Bar Chart

Style-agnostic SVG bar chart using CSS custom properties.

python 9 params

Preview

Quarterly revenueQ1: 12.012Q1Q2: 19.019Q2Q3: 8.08Q3Q4: 15.015Q4
Arguments
bar_chart(data=[12, 19, 8, 15], labels=['Q1', 'Q2', 'Q3', 'Q4'], title='Quarterly revenue')

Usage

views.py
python
from djust import LiveView
from djust.components import BarChart


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = BarChart(data=[12, 19, 8, 15], labels=['Q1', 'Q2', 'Q3', 'Q4'], title='Quarterly revenue')
my_template.html
django
{{ component }}

Parameters

NameTypeDefaultDescription
datalist | NoneNoneList of numeric values
labelslist | NoneNoneList of category labels
titlestr | NoneNoneOptional chart title
widthint400SVG width (default: 400)
heightint250SVG height (default: 250)
colorstr''Bar fill color
show_valuesboolTrueShow value labels above bars
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.bar_chartSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 6 of this component's classes at line 2069, 2070, 2071, 2072, 2074, 2075. Override those rules, or the custom properties they read, in a stylesheet loaded after it.