SvgCharts (svg_charts v0.5.1)

Copy Markdown View Source

SVG chart renderer powered by charts-rs.

Takes a JSON configuration with a "type" field and returns an SVG string.

Supported chart types

  • "bar" - Vertical bar chart
  • "horizontal_bar" - Horizontal bar chart
  • "line" - Line chart
  • "pie" - Pie chart
  • "radar" - Radar/spider chart
  • "scatter" - Scatter plot
  • "candlestick" - Candlestick chart
  • "heatmap" - Heatmap
  • "table" - Table
  • "multi" - Multi-chart composition

Examples

{:ok, svg} = SvgCharts.render(%{
  "type" => "bar",
  "title_text" => "Downloads",
  "series_list" => [
    %{"name" => "MDEx", "data" => [120.0, 200.0, 150.0]}
  ],
  "x_axis_data" => ["Jan", "Feb", "Mar"]
})

svg = SvgCharts.render!(~s({"type": "line", "series_list": [{"name": "A", "data": [1.0, 2.0]}], "x_axis_data": ["X", "Y"]}))

Legend layout

Chart options are passed through to charts-rs. Use "legend_margin" to position a legend below title text:

%{
  "title_text" => "Framework Comparison",
  "sub_title_text" => "Phoenix vs. Rails vs. Next.js",
  "legend_margin" => %{"top" => 60}
}

Set "legend_show" => false to omit the legend, which is often useful for a single-series chart.

Summary

Functions

Render a chart to SVG.

Same as render/1 but raises on error.

Functions

render(data)

@spec render(map() | String.t()) :: {:ok, String.t()} | {:error, String.t()}

Render a chart to SVG.

Accepts a map or a JSON string. Must include a "type" field.

render!(data)

@spec render!(map() | String.t()) :: String.t()

Same as render/1 but raises on error.