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.| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Chart width in points. |
height | number | — | Chart height in points. |
data | ChartDataPoint[] | — | Data points ({ label, value, color? }). |
color | string | "#1a365d" | Default bar color (hex). Per-item color overrides this. |
showLabels | boolean | true | Show category labels on the X axis. |
showGrid | boolean | false | Show horizontal grid lines. |
showValues | boolean | false | Show value labels above each bar. |
title | string | — | Chart title displayed above the chart. |
LineChart
Multi-series line chart with optional data points and grid.| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Chart width in points. |
height | number | — | Chart height in points. |
series | ChartSeries[] | — | Series array ({ name, data: number[], color? }). |
labels | string[] | — | X-axis labels (one per data point). |
showPoints | boolean | false | Show dots at data points. |
showGrid | boolean | false | Show horizontal grid lines. |
title | string | — | Chart title. |
PieChart
Pie or donut chart with optional legend.| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Chart width in points. |
height | number | — | Chart height in points. |
data | ChartDataPoint[] | — | Slices ({ label, value, color? }). Each slice should have a color. |
donut | boolean | false | Cut out the center to create a donut chart. |
showLegend | boolean | false | Show a legend beside the chart. |
title | string | — | Chart title. |
AreaChart
Multi-series area chart — like LineChart but with semi-transparent fill under each line.| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Chart width in points. |
height | number | — | Chart height in points. |
series | ChartSeries[] | — | Series array ({ name, data: number[], color? }). |
labels | string[] | — | X-axis labels. |
showGrid | boolean | false | Show horizontal grid lines. |
title | string | — | Chart title. |
DotPlot
Scatter plot for (x, y) data with multiple groups and optional axis labels.| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Chart width in points. |
height | number | — | Chart height in points. |
groups | DotPlotGroup[] | — | Groups ({ name, color?, data: [x, y][] }). |
xMin / xMax | number | — | X-axis range (auto-computed if omitted). |
yMin / yMax | number | — | Y-axis range (auto-computed if omitted). |
xLabel | string | — | X-axis label. |
yLabel | string | — | Y-axis label. |
showLegend | boolean | false | Show legend. |
dotSize | number | 4 | Dot radius in points. |
Shared types
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
- Use a charting library to produce an SVG string
- Pass the string to
<Svg content={svgString} /> - Forme renders the SVG shapes directly into the PDF as vector graphics
D3 example
D3 can render to a virtual DOM usingd3-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
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
<Image> instead.
Tips
- Set explicit
width,height, andviewBoxon 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