An htmx extension for rendering Vega-Lite charts from JSON —
add hx-ext="plot" to any element and point it at a JSON spec.
GitHub ·
Powered by a service worker, works offline after first load.
⧗ registering…
Include htmx and hx-plot, then use hx-ext="plot" on any element.
<script src="https://unpkg.com/htmx.org@2"></script>
<script src="https://c-cube.github.io/hx-plot/hx-plot.full.min.js"></script>
<script id="spec" type="application/json">
{
"mark": "point",
"data": {"values": [{"x": 1, "y": 2}, {"x": 2, "y": 4}]},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"}
}
}
</script>
<div hx-ext="plot" hx-plot="#spec" hx-target="#chart"></div>
<div id="chart"></div>
<div hx-ext="plot"
hx-get="/api/chart"
hx-trigger="load"
hx-target="#chart"></div>
<div id="chart"></div>
<div hx-ext="plot"
hx-get="/api/chart"
hx-trigger="load, every 2s"
hx-target="#chart"
hx-swap="innerHTML transition:true"></div>
<div id="chart" style="view-transition-name: my-chart"></div>