Skip to main content

Charts

Forme includes five engine-native chart components that render directly to PDF vector graphics. Charts are processed by the Rust engine — no SVG intermediary, no external dependencies. The output is crisp at any zoom level and adds minimal file size.

Built-in chart components

BarChart

Simple category bar chart with optional grid, value labels, and title.

LineChart

Multi-series line chart with optional data points and grid.

PieChart

Pie or donut chart with optional legend.

AreaChart

Multi-series area chart — like LineChart but with semi-transparent fill under each line.

DotPlot

Scatter plot for (x, y) data with multiple groups and optional axis labels.

Shared types

See the Components reference for the full prop tables.

Custom charts with SVG

For charts beyond what the built-in components offer, Forme renders SVG content via the <Svg> component. Any charting library that outputs SVG strings can be used to embed charts in your PDFs.

The pattern

  1. Use a charting library to produce an SVG string
  2. Pass the string to <Svg content={svgString} />
  3. Forme renders the SVG shapes directly into the PDF as vector graphics

D3 example

D3 can render to a virtual DOM using d3-node or jsdom on the server side. Here is a bar chart example:

Simple charts without a library

For basic charts, you can write SVG strings directly:

Supported SVG elements

Forme’s SVG renderer supports the following elements:
  • <rect> - rectangles, rounded rectangles
  • <circle> - circles
  • <ellipse> - ellipses
  • <line> - straight lines
  • <polyline> - connected line segments
  • <polygon> - closed shapes
  • <path> - arbitrary paths (M, L, H, V, C, Q, A, Z commands)
  • <g> - groups with transform support
Supported attributes: fill, stroke, stroke-width, transform (translate, scale, rotate), opacity.

What’s not supported

  • <text> inside SVG (use Forme’s <Text> component instead, positioned alongside the SVG)
  • CSS styling inside SVG (use inline attributes)
  • <clipPath>, <mask>, <filter>, <gradient> (these are not yet supported)
  • <use>, <defs>, <symbol> references
For charts that rely on these features, consider rendering the chart to a PNG image and using <Image> instead.

Tips

  • Set explicit width, height, and viewBox on the <Svg> component for consistent sizing
  • Use server-side rendering (jsdom, d3-node) to produce SVG strings in Node.js
  • Keep chart SVGs simple. The fewer elements, the smaller the PDF and the faster the render.
  • For complex charts with many data points, consider simplifying (fewer grid lines, fewer labels) since PDF charts are static and don’t need interactivity