Skip to content

AltairChart

Render an Altair chart through the declarative visualization adapter.

Import from hedron_charts import AltairChart
Distribution hedron-charts[altair]
Backend activity No
Normal render mode RenderMode.FRAGMENT

Live demo

AltairChart outputAccessible static preview with a text conclusion.

The preview is a local docs simulation (not a running Hedron server). Interactive demos show a “Simulated HTMX” trace when applicable.

Install the optional provider before importing this component:

pip install "hedron-charts[altair]>=1.0.0,<2.0"

Basic use

from hedron_charts import AltairChart
import altair as alt
chart = alt.Chart({'values': [{'week': 'W1', 'deployments': 3}, {'week': 'W2', 'deployments': 5}]}).mark_bar().encode(x='week:N', y='deployments:Q')

component = AltairChart(chart, title='Deployments per week', description='Deployments peaked in week four.')

Compose under Page for full documents, or return from a fragment route for HTMX swaps.

How it works

The server compiles the chart specification under output and accessibility limits. Hedron owns the embedding contract instead of accepting arbitrary active markup.

The server emits bounded, non-executable JSON and accessible metadata. The interactive visual requires the corresponding vendored browser host/runtime; these adapters remain Experimental and fail closed when the runtime is unavailable.

Constructor and parameters

AltairChart(chart, *, title=None, description=None, alt=None, waiver=None)
Parameter Type Meaning
chart Altair Chart Declarative chart object.
title / description / alt str | None Accessible metadata.
waiver str | None Reviewed exception.

Composition and backend behavior

Keep AltairChart at the smallest semantic boundary. Fragment routes should return only the replaced region and preserve stable target IDs across success, validation, empty, loading, and error responses.

AltairChart renders data the server already prepared. Keep queries, authorization, and redaction on the route or data source — do not treat the component as a place for side effects.

Accessibility

Use encodings that remain distinguishable without color and provide a narrative or table alternative.

Security

Escaping and SafeUrl / TrustedHtml are framework concerns; authorization and data exposure remain application code. Redact secrets before rendering.

Common mistakes

  • Validate data volume and avoid specifications that fetch remote resources in the browser.
  • Do not copy docs-preview JavaScript into an application server.

Testing

from hedron import RenderMode, render

result = render(component, mode=RenderMode.FRAGMENT)
assert result.html
assert not result.diagnostics

Charts guide · Charts API · hedron-charts package