Chart
Chart renders Matplotlib, Plotly, Altair, or raw SVG and HTML outputs in a single component.
Quick Start
Plotly and Altair
If your figure object exposes to_html(), Chart can render it directly.
For Plotly, include_js=True asks Plotly to include its JavaScript from a CDN. If your layout already loads Plotly globally, leave include_js=False.
Raw SVG or HTML
Raw strings require explicit opt-in for safety:
Backend Inference
If you pass a Matplotlib or Plotly/Altair object, Chart will infer the backend automatically. Raw strings always require backend to be specified.
Sizing and Responsiveness
responsive=Trueaddsw-100to the wrapper.- Use
widthandheightfor fixed sizing.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
figure |
Any |
required | Matplotlib figure, Plotly/Altair chart, or trusted raw string. |
backend |
matplotlib \| plotly \| altair \| svg \| html \| None |
None |
Explicit renderer. Required for raw strings. |
include_js |
bool |
False |
Include Plotly JavaScript when rendering Plotly charts. |
responsive |
bool |
True |
Adds w-100 to the wrapper. |
width |
str \| int \| None |
None |
Wrapper width. Integers become pixel values. |
height |
str \| int \| None |
None |
Wrapper height. Integers become pixel values. |
allow_unsafe_html |
bool |
False |
Required for raw SVG/HTML strings. |
**kwargs |
Any |
Extra wrapper attributes. |
Theming
Chart does not auto-theme plots. Use your chart library to set colors for dark mode and match your theme palette.
Security Notes
If you render raw SVG or HTML, only use trusted content. Set allow_unsafe_html=True only when you control the source.
API Reference
faststrap.components.display.chart.Chart(figure, *, backend=None, include_js=False, responsive=True, width=None, height=None, allow_unsafe_html=False, **kwargs)
Render a chart from common Python plotting backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
Any
|
Matplotlib figure, Plotly/Altair chart, or raw SVG/HTML string. |
required |
backend
|
ChartBackend | None
|
Explicit backend name. If None, attempts to infer from object. |
None
|
include_js
|
bool
|
Include Plotly JS when rendering Plotly charts. |
False
|
responsive
|
bool
|
Apply responsive sizing classes. |
True
|
width
|
str | int | None
|
Optional width (px or CSS string). |
None
|
height
|
str | int | None
|
Optional height (px or CSS string). |
None
|
allow_unsafe_html
|
bool
|
Allow raw HTML/SVG strings to be embedded. |
False
|
**kwargs
|
Any
|
Additional HTML attributes for the wrapper. |
{}
|