svg_chart
scalar · LOAD svg_charts
svg_chart(ANY) -> VARCHARDraws several series from a list of structs.
SELECT svg_chart(list({'hour': hour, 'nsw': nsw, 'qld': qld} ORDER BY hour))
FROM readings;A scalar function over one LIST of STRUCTs, one struct per point — which is exactly what DuckDB’s built-in list() aggregate produces.
The first struct field is the x axis unless options.x names another. Every remaining numeric field becomes a series, named after the field: those names are what the tooltip shows and what options.series entries match on. Values that are NULL or infinite leave a gap in the line and show as - in the tooltip.
The reliable spelling
This is also the form to reach for when order matters, because list() can sort and a bare aggregate cannot:
SELECT regionid, svg_chart(list({'x': ts, 'y': avg_rrp} ORDER BY ts))
FROM prices_monthly GROUP BY regionid;svg_line_chart(ts, y ORDER BY ts) does not work — see svg_line_chart.
Options
The optional second argument is a DuckDB STRUCT, not a JSON string, so DuckDB’s own parser checks it and type errors surface at bind time. Keys are matched ignoring case and underscores. charts has both tables — the chart-level keys and the per-series ones — with their defaults.
Requires LOAD svg_charts.