Skip to content

chart://

Producer-only chart renderer wrapping go-analyze/charts, a pure-Go ECharts-style chart library. Turns a structured payload into a PNG / SVG / JPG / base64 image. Supports line, bar, horizontal-bar, pie, doughnut, candlestick (OHLC), radar, funnel, heatmap, scatter, violin, and stacked variants. Also accepts raw ECharts JSON option objects for full-fidelity ECharts rendering.

Producer-only — CreateConsumer returns ErrConsumerNotSupported.

URI shape

chart://<name>?type=line&width=800&height=400&format=png&theme=light

Parameters

Param Type Default Description
type enum line line, bar, horizontal-bar, pie, doughnut, candlestick, radar, funnel, heatmap, scatter, violin, echarts (raw ECharts option JSON).
width integer 800 Output width (px for PNG/JPG; user units for SVG).
height integer 400 Output height.
format enum png png, svg, jpg/jpeg, base64-png/base64-svg/base64-jpg, data-uri-png/data-uri-svg/data-uri-jpg.
theme enum light light, dark, ant, vintage, westeros, wonderland, walden, natural, grafana.
title string — Chart title (overrides body.title).
subtitle string — Subtitle.
xLabel, yLabel string — Axis labels (override body fields).
fontFamily enum notosans notosans, notosans-bold, roboto.
showLegend boolean true Series legend.
showSymbols boolean true Data-point markers (line / scatter).
smoothLine boolean false Bezier smoothing for line charts.
fillArea boolean false Fill area under line series.
stack boolean false Stack series.
horizontal boolean false Alias for type=horizontal-bar.
candleStyle enum filled filled or hollow (candlestick body).
candleWidth number 0.8 Candle body width ratio (0.0–1.0).
padding integer 10 Chart padding (px).

Body shape

Per chart type:

Chart types Expected body
line, bar, horizontal-bar, pie, doughnut, radar, funnel, scatter, violin {"values": [[...], [...]], "labels": [...], "series": ["A","B"], "title": "...", "xLabel": "...", "yLabel": "..."} or [][]float64 (multi-series) or []float64 (single-series).
candlestick {"ohlc": [[open, high, low, close], ...], "labels": [...]}.
echarts (or format=echarts-png|echarts-svg|echarts-jpg) A JSON string containing the full ECharts option object — rendered via RenderEChartsToPNG / ...SVG / ...JPG.

Headers

Written

Header Description
Content-Type image/png, image/svg+xml, image/jpeg, or text/plain (base64 / data-uri variants).
chart.type Chart type.
chart.format Output format.
chart.width, chart.height Configured dimensions.
chart.bytes Raw image size in bytes.

The body becomes the rendered image bytes (for native PNG / SVG / JPG), the base64 string (for base64-*), or the full data:image/...;base64,... URI (for data-uri-*).

Examples

Simple line chart:

- set-body:
    starlang: |
      %sl 2.0
      output application/json
      input payload
      ---
      {
        "values":  [[10, 25, 15, 40, 30]],
        "labels":  ["Mon","Tue","Wed","Thu","Fri"],
        "series":  ["Visitors"],
        "xLabel":  "Day",
        "yLabel":  "Count"
      }
- target: chart://visitors?type=line&width=900&height=400&theme=ant

Embed in an HTML report (data URI):

- set-body:
    starlang: |
      %sl 2.0
      output application/json
      input payload
      ---
      { "values": [[42, 38, 27]], "labels": ["A","B","C"] }
- target: chart://share?type=pie&format=data-uri-png
- transform:
    starlang: |
      %sl 2.0
      output text/html
      input payload
      ---
      "<img src=\"" ++ payload ++ "\"/>"

Candlestick from OHLC rows:

- set-body:
    starlang: |
      %sl 2.0
      output application/json
      input payload
      ---
      { "ohlc": payload.bars, "labels": payload.dates }
- target: chart://ohlc?type=candlestick&theme=dark&candleStyle=hollow

Raw ECharts option for advanced configurations:

- set-body:
    starlang: 'echarts_option_json(payload)'
- target: chart://custom?type=echarts&format=png

Behavior notes

  • Two-rail surface — the type=<simple> rail uses go-analyze/charts's high-level API (uniform across chart types). The echarts type drops to RenderECharts* for full ECharts compatibility.
  • Format and output coupling — format=base64-* returns a string body with Content-Type: text/plain. format=data-uri-* returns data:image/...;base64,... ready for an <img src>. Native formats keep image/... content types and raw bytes.
  • Padding default is intentionally small (10 px) — many themes draw axes / titles right up to the edge otherwise.
  • Theme set — chart themes match go-analyze/charts's named palettes; see the library's docs for the exact look.
  • Both Out() and In() are written. The In() body is overwritten so the next pipeline step sees the rendered chart, not the input data.

Source

pkg/component/chart/chart.go, pkg/component/chart/render.go

See also

  • pdf — combine chart output with HTML for richer reports.
  • template — render the surrounding HTML before the chart.
  • http-server — serve charts as images.