AshDyan.Charts.SVG (AshDyan v0.6.0)

Copy Markdown View Source

Server-side SVG renderer for AshDyan.Result.

Produces a standalone <svg> string (no JavaScript, no external assets) so a result can be rendered to an image in emails, PDFs, or any non-JS context. The visual conventions (palette, chart-type defaults) match AshDyan.Charts.to_chartjs/2 / to_echarts/2.

Supported chart types

  • :bar — vertical bars, one group per label, one bar per series.
  • :line — polylines with point markers.
  • :area — like :line with a translucent fill under each series.
  • :pie / :donut — single-series slices (donut has an inner radius).
  • :histogram — contiguous bars (no gaps between bins).
  • :scatter — paired two-series points, or per-series points at index x.

chart_type is optional; AshDyan.Charts.recommend/1 is used when omitted.

Example

{:ok, result} = AshDyan.run(spec)
svg = AshDyan.Charts.to_svg(result)
# or: AshDyan.Charts.to_svg(result, :line, width: 800, height: 400)

Options

  • :width — SVG width in px (default 640).
  • :height — SVG height in px (default 400).
  • :title — chart title text (default nil).

Summary

Functions

Render a result as a standalone SVG string.

Types

option()

@type option() ::
  {:width, pos_integer()}
  | {:height, pos_integer()}
  | {:title, String.t() | nil}

Functions

render(result, chart_type \\ nil, opts \\ [])

@spec render(AshDyan.Result.t(), AshDyan.Charts.chart_type() | nil, [option()]) ::
  {:ok, String.t()} | {:error, AshDyan.Error.t()}

Render a result as a standalone SVG string.