Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chart Elements

AltairChart

Renders an Altair / Vega-Lite chart.

import altair as alt

chart = alt.Chart(data).mark_bar().encode(
    x='category',
    y='value',
)

sc.AltairChart(chart)
ArgumentTypeMeaning
chartAltair chart or dictThe chart specification
widthsize keywordChart width
visiblebool | PropertyDefault True

Properties: chart.

AltairChart accepts either an Altair chart object (anything with a to_dict() method) or a plain Vega-Lite dictionary. Altair itself is an optional dependency: the component does not import it.

To update a chart, call set_chart() or set the chart property with a new specification:

with sc.AltairChart(chart) as view:
    @state.data.on_change
    def _():
        view.set_chart(alt.Chart(state.data.get()).mark_line())