Usage
{{< hw t="graph" from = "data:releases" [x = "date"] [y = "version,build"] [class = "line"] [header = "Release Timeline"] [description = "Date"] [meta = "Version"] [text = "Source: releases.yaml"] [id = "my-graph"] [blockClass = "hw-graph"] >}}XY chart from yaml/json/csv or front-matter data. Param cascade: site.Params.graph → page.Params.graphs.{id} → shortcode param.
Description
Renders a responsive Chart.js XY chart sized to its parent container. Data is loaded at build time from assets/ using Hugo transform.Unmarshal (no runtime fetch), or supplied inline in front matter. Multiple traces are defined by comma-separating field names in the y param. Styling cascades from site.Params.graph through named graph blocks in page front matter to per-shortcode overrides.
Parameters
indicates required parameter
from =
"string"REQUIRED
Path to data file relative to
assets/ (yaml/json/csv), OR frontmatter:dot.path to walk page.Params, OR omit and supply data: in the graphs.{id} front-matter block.x =
"string"first field
Field name for the x-axis (labels). Defaults to the first field in the data.
y =
"string"all non-x fields
Comma-separated field names to plot as separate traces. Defaults to all fields except x.
class =
"string"site.Params.graph.type (line)
Chart type:
line | bar | scatter | areaheader =
"string"empty
Chart title displayed above the plot area
description =
"string"empty
X-axis label
meta =
"string"empty
Y-axis label
text =
"string"empty
Caption rendered below the chart (markdownified)
id =
"string"auto (block ordinal)
Identifies this graph instance. Also used as a lookup key into
page.Params.graphs.{id} so all config can live in front matter.blockClass =
"string"empty
CSS class on the outer wrapper div (applied by the hw dispatcher). Use to set height via CSS rather than inline style.
Examples
Minimal — file data, auto-detected fields
{{<hw t="graph" from="data:releases">}}x = first field, all remaining fields become traces
Explicit axes and chart type
{{<hw t="graph" from="data:releases" x="date" y="version,build" class="bar" header="Release History">}}Two bar traces; header shown as chart title
Inline front-matter data (Form B) — self-contained page
{{<hw t="graph" id="banana-chart">}}Front matter contains the full graph definition — shortcode stays minimal.
See Front-matter data (Form B) section below.
Two graphs on one page via front-matter blocks
{{<hw t="graph" id="prices">}}
{{<hw t="graph" id="volumes">}}Each id resolves to its own
graphs.{id} block in front matterNamed front-matter data, standalone shortcode (Form A)
{{<hw t="graph" from="frontmatter:data.banana-prices" x="month" y="price">}}Walks
page.Params.data["banana-prices"] — data lives in front matter, config stays in shortcodeSparkline — no chrome, fixed height
{{<hw t="graph" from="data/temps.json" x="time" y="celsius" showAxis="none" showLabels="none" showGrid="none" showLegend="false" height="80px">}}All display controls suppressed; height set inline
Additional Information