# Charts and every chart modifier
Start with a one-line chart, then add only the options you need. Chart rendering depends on the output format and the way the document is generated; use the matrix below before building a large report.
**Before you start:** Choose the fields and relationships in [Choose information](#choose-data). For an orientation and the format checklist, open [Find the right merge tag](#merge-tags).
#### Charts
Render **nine chart styles** inline in your generated documents — bar, column, pie, donut, pivot, stacked, clustered, line, and area. Charts use a prepared PNG image on supported paths, with browser rendering for interactive work and an Apex rasterizer for server work. HTML can also use CSS chart blocks or opt-in browser-only SVG. Excel output does not embed chart-tag images. Test the exact entry point you intend to use:
| Output | How charts get there |
| ------------------ | --------------------------------------------------------------------- |
| HTML → browser | `` |
| HTML → PDF | Same `` — Flying Saucer (`Blob.toPdf`) fetches it server-side |
| Word `.docx` | `` referencing a PNG embedded in `word/media/` |
| Word → PDF | Word → HTML → PDF chain; the embedded PNG flows through transparently |
| PowerPoint `.pptx` | `` referencing a PNG in `ppt/media/` |
| Excel `.xlsx` | (Coming in a follow-up release) |
**Zero external callouts.** The chart engine is 100% native Apex — same constraint that makes Portwood suitable for AppExchange security review and managed-package customers. Charts work in Flow actions, batch jobs, Queueables, and Apex tests as well as the runner LWC.
**Two authoring paths:**
1. **`{Chart:relationship:field:style:opts}`** — one-line tag. The engine resolves bucket data via SOQL aggregate (constant cost regardless of row count), rasterizes to PNG, embeds the image. Works on supported Word, HTML/PDF, Canvas, and PowerPoint paths; Excel image embedding is not supported. **This is the canonical path — use it for 95% of cases.**
2. **`{#ChartBucket:relationship:field}…{/ChartBucket}`** — hand-authored loop. You write the chart HTML body yourself with `{key}` / `{count}` / `{percent}` placeholders. Use only when you need a custom layout the engine doesn't ship (e.g., embedded sparklines inside a table cell).
#### One-line `{Chart:...}` blocks
A single tag that expands into a complete chart image at render time. **Tag syntax:**
```
{Chart:RELATIONSHIP:FIELD:STYLE:OPTS}
```
| Position | Required | Meaning |
| -------------- | -------- | ------------------------------------------------------ |
| `RELATIONSHIP` | yes | Child relationship name on the parent record (one-hop) |
| `FIELD` | yes | Field on the child to group by |
| `STYLE` | no | One of nine styles (default: `bar`) |
| `OPTS` | no | `key=value&key=value` modifiers |
**All nine styles:**
| Style | Visual | Cross-tab? | Best for |
| ----------- | ---------------------------------------------------------------------------- | ---------- | -------------------------------------------------------- |
| `bar` | Horizontal bar per bucket, label left, count+% right | no | One question, one dimension. Long category labels. |
| `column` | Vertical bar per bucket, labels under, % above | no | One question, one dimension. Short labels. |
| `pie` | Pie chart with right-side legend showing count + % | no | "Share of total" framing, ≤8 slices |
| `donut` | Pie with a center hole, same legend | no | Same as pie, lighter visual weight |
| `pivot` | Cross-tab table — rows = buckets, cols = `groupBy` values + Total | required | Numeric matrix readout. CSS-bar path (HTML-friendly). |
| `stacked` | Horizontal stacked bar — one row per bucket, segments by `groupBy` | required | "How does each row break down across the 2nd dimension?" |
| `clustered` | Vertical clustered bars — one cluster per bucket, mini-bar per col | required | Side-by-side comparison across the 2nd dimension |
| `line` | Polyline through (bucket index, count). Multi-series when `groupBy` present. | optional | Trend / ordering matters. Single or multi-series. |
| `area` | Line chart with semi-transparent fill below each series | optional | Trend + accumulated volume |
**Worked examples** (against the canonical Commute Survey Demo — 425 responses, 6 modes, 2 locations):
```
{Chart:Survey_Responses__r:Selected_Answer__c:bar:title=Commute Mode Distribution}
{Chart:Survey_Responses__r:Selected_Answer__c:column:title=Commute Mode (Vertical)}
{Chart:Survey_Responses__r:Selected_Answer__c:pie:title=Commute Mode Share}
{Chart:Survey_Responses__r:Selected_Answer__c:donut:title=Commute Mode Share (Donut)}
{Chart:Survey_Responses__r:Selected_Answer__c:stacked:groupBy=Location__c&colSort=8000 Marina,3260 Bayshore&title=Location Mix per Mode}
{Chart:Survey_Responses__r:Selected_Answer__c:clustered:groupBy=Location__c&colSort=8000 Marina,3260 Bayshore&title=Mode by Location Comparison}
{Chart:Survey_Responses__r:Selected_Answer__c:line:groupBy=Location__c&colSort=8000 Marina,3260 Bayshore&title=Commute Trend by Location}
{Chart:Survey_Responses__r:Selected_Answer__c:area:groupBy=Location__c&colSort=8000 Marina,3260 Bayshore&title=Commute Volume by Location}
{Chart:Survey_Responses__r:Selected_Answer__c:pivot:groupBy=Location__c&colSort=8000 Marina,3260 Bayshore&title=Mode by Location (Table)}
```
#### Complete modifier reference
Modifiers come after the style, joined with `&`. **Order doesn't matter.** Values containing `&` or `=` are not supported (use `where=` for SOQL with operators — see below).
| Modifier | Applies to | Example | What it does |
| ------------- | --------------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `title=` | all styles | `title=How satisfied are you with your role?` | Chart header text drawn above the chart. Becomes the `` attribute on the HTML side. |
| `width=` | all styles | `width=420` | Logical-pixel width of the chart. Defaults: 540 (stacked/clustered), 500 (bar/column/line/area), 360 (pie/donut). Word/PDF downsample bigger PNGs for free AA. |
| `height=` | all styles | `height=240` | Logical-pixel height. Defaults vary per style (see source); bar auto-grows by bucket count. |
| `fontSize=` | all styles | `fontSize=16` | Axis-label size in pixels. Default 12; titles and other text scale with it, keeping their proportions. Raise it when the chart lands in a small frame. On a Canvas chart use the **Label size** box rather than writing the tag. Honoured by all three renderers — browser, Word/PowerPoint, and HTML-to-PDF. (v3.56+) |
| `where=` | all styles | `where=Survey_Question__r.Display_Order__c=1` | SOQL fragment appended to the chart's `WHERE`. Identifier-only, sanitized through the same keyword blocklist as Query Builder. Forces server-side aggregation. |
| `groupBy=` | stacked/clustered/pivot/line/area | `groupBy=Department__c` | Cross-tab dimension. **Required** for `stacked`/`clustered`/`pivot`; **optional** for `line`/`area` (omit → single-series). Field on the same child object as `FIELD`. |
| `colSort=` | stacked/clustered/pivot/line/area | `colSort=Engineering,Sales,Marketing,Support,Operations` | Author-controlled column ordering. Named values appear first in this order; remaining values alpha-sorted; synthetic `Total` always last (pivot path only). |
| `colors=` | all styles | `colors=#1e40af,#b91c1c,#16a34a` | Override the default 8-color palette. Cycles by row/series index. Each color is `#hex` (6 chars). |
| `split=` | all (bucket-shape only) | `split=;` | Multi-select delimiter. Each respondent's pick contributes to every value they selected. Percentages sum to >100% by design. |
| `scale=` | all (raster path only) | `scale=2` | Supersample multiplier. Default 1 for stacked/clustered/line/area, 2 for bar/column/pie/donut. Larger = sharper PNG but slower; 4 is the practical ceiling. |
| `htmlRender=` | HTML browser preview | `htmlRender=svg` | (HTML only, opt-in.) Inline `