# Mermaid, Graphviz & Chart to PNG, SVG or PDF (`fluidfaith/mermaid-chart-renderer`) Actor

Render Mermaid, Graphviz DOT, Vega-Lite, Vega, Chart.js or SVG code to a PNG, SVG or PDF link for AI agents and MCP. Bad code returns the exact error with line number so the agent can fix and retry. $0.003 per diagram, errors free.

- **URL**: https://apify.com/fluidfaith/mermaid-chart-renderer.md
- **Developed by:** [FFS Marketing](https://apify.com/fluidfaith) (community)
- **Categories:** Developer tools, AI, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00 / 1,000 diagram or chart rendereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Mermaid, Graphviz & Chart to PNG, SVG or PDF

**Turn diagram or chart code into an image file your agent can share.** Send Mermaid (flowchart, sequence, class, ER, gantt, pie, mindmap, timeline and more), Graphviz DOT, a Vega-Lite or Vega spec, a Chart.js config or raw SVG, and get back a PNG, SVG or PDF as a public link. When the code is wrong you get the parser's exact error, the line number and the offending line, so the agent can fix it and call again.

**Works as a tool for AI agents.** Add it to Claude, ChatGPT, Cursor, VS Code or any MCP client through Apify's MCP server (`https://mcp.apify.com/?tools=fluidfaith/mermaid-chart-renderer`), or call it with one API request. JSON in, JSON out. Setup is in [Use it from an agent](#use-it-from-an-agent).

**Costs $0.003 per diagram rendered.** Code with errors is free, and your maximum charge per run is never exceeded.

#### Why use it

- **Agents write diagram code all day but cannot show it.** Slack, email, n8n, chat replies, Google Docs and PDFs need an image, and most agents have no headless browser to run mermaid-cli.
- **Errors an LLM can act on.** `Parse error on line 3`, the text of line 3 and a short fix hint come back as fields, not a stack trace. Errors are not charged, so retrying is free until it renders.
- **Six languages in one tool.** Mermaid, Graphviz (8 layout engines), Vega-Lite, Vega, Chart.js and SVG. Leave `type` empty and it is detected from the code.
- **PNG, SVG or PDF.** PNG at 2x for sharp phone and retina screens, SVG as a file and inline markup, PDF sized to the diagram for print.
- **Themes.** Mermaid default, dark, neutral and forest; dark also gives charts light text on a dark background. Any background color, or transparent.
- **Offline and safe.** Rendering never touches the network, scripts in SVG are stripped, Mermaid runs in strict mode.

### What you get

| Field | What it is |
|---|---|
| `status` | `OK` (rendered and charged) or `ERROR` (not charged). |
| `fileUrl` | Public link to the PNG, SVG or PDF. |
| `type`, `format` | What was rendered (`mermaid`, `graphviz`, `vegalite`, `vega`, `chartjs`, `svg`) and the output format. |
| `width`, `height` | Size of the diagram in CSS pixels. |
| `pixelWidth`, `pixelHeight` | Size of the PNG (width x scale). |
| `svg` | With SVG output: the SVG markup itself (under 100 KB), ready to embed. |
| `error` | The parser's message, for example `Parse error on line 3: ... Expecting 'SQE', got 'PS'`. |
| `errorLine`, `errorColumn` | Where the error is, when the parser says. |
| `errorExcerpt` | The text of that line. |
| `hint` | One line on what usually fixes this kind of error. |
| `warnings` | For example outside images that were not loaded. |

The run summary in the `OUTPUT` record has `status` (`OK`, `PARTIAL`, `ERROR`), counts, and a short list of every diagram with its link or error.

### Input

One diagram:

```json
{
  "code": "flowchart LR\n  A[Agent writes Mermaid] --> B{Valid?}\n  B -- yes --> C[PNG link]\n  B -- no --> D[Error with line number]",
  "format": "png"
}
```

Many diagrams in one run (each one billed only if it renders):

```json
{
  "diagrams": [
    { "name": "deploy-flow", "code": "digraph { rankdir=LR; build -> test -> deploy }" },
    { "name": "weekly-runs", "type": "chartjs", "code": { "type": "bar", "data": { "labels": ["Mon", "Tue"], "datasets": [{ "label": "Runs", "data": [12, 19] }] } } },
    { "name": "arch", "sourceUrl": "https://github.com/owner/repo/blob/main/docs/architecture.mmd", "format": "svg" }
  ],
  "theme": "dark"
}
```

| Field | Default | What it does |
|---|---|---|
| `code` | | The code of one diagram as text (up to 200,000 characters). Inside `diagrams`, Vega-Lite, Vega and Chart.js specs can also be JSON objects. |
| `type` | detected | `mermaid`, `graphviz`, `vegalite`, `vega`, `chartjs` or `svg`. Detection: `<svg` is SVG, `digraph`/`graph` is Graphviz, JSON with a vega-lite `$schema` is Vega-Lite, JSON with `type` + `data.datasets` is Chart.js, anything else is Mermaid. |
| `diagrams` | | Up to 100 `{ code, type, name, format, theme, background, engine, sourceUrl }` objects. |
| `sourceUrl` | | Fetch the code from a public link instead: a raw file, a GitHub file page or a gist (up to 1 MB). |
| `format` | `png` | `png`, `svg` or `pdf`. Chart.js gives PNG or PDF. |
| `theme` | `default` | `default`, `dark`, `neutral`, `forest`. |
| `background` | `white` | Any CSS color, or `transparent`. Dark theme defaults to `#1e1e1e`. |
| `scale` | `2` | PNG pixel density, 1 to 4. |
| `width`, `height` | `800`, `500` | Chart.js canvas size. |
| `graphvizEngine` | `dot` | `dot`, `neato`, `fdp`, `sfdp`, `circo`, `twopi`, `osage`, `patchwork`. |
| `includeSvgText` | `true` | Put the SVG markup in the result row too. |
| `timeoutSecsPerDiagram` | `20` | A diagram that takes longer becomes an ERROR row (free). |
| `maxConcurrency` | `2` | Diagrams rendered at the same time (1 to 4). |

### Output

```json
{
  "name": "diagram-1",
  "type": "mermaid",
  "format": "png",
  "status": "OK",
  "fileUrl": "https://api.apify.com/v2/key-value-stores/.../records/diagram-1-e15b79.png",
  "width": 636, "height": 210, "pixelWidth": 1272, "pixelHeight": 420,
  "bytes": 32831, "error": null, "warnings": []
}
```

And when the code is wrong (not charged):

```json
{
  "name": "diagram-1",
  "type": "mermaid",
  "status": "ERROR",
  "fileUrl": null,
  "error": "Parse error on line 3:\n...B -->> C[[Oops\n----------------------^\nExpecting ...",
  "errorLine": 3,
  "errorExcerpt": "    B -->> C[[Oops",
  "hint": "Check the diagram keyword on the first line (flowchart TD, sequenceDiagram, ...) and the arrow syntax near the line shown."
}
```

### Use it from an agent

#### Through Apify's MCP server (Claude, ChatGPT, Cursor, VS Code, any MCP client)

```json
{
  "mcpServers": {
    "diagram-renderer": {
      "url": "https://mcp.apify.com/?tools=fluidfaith/mermaid-chart-renderer",
      "headers": { "Authorization": "Bearer <APIFY_TOKEN>" }
    }
  }
}
```

**Claude Code:** `claude mcp add --transport http diagram-renderer "https://mcp.apify.com/?tools=fluidfaith/mermaid-chart-renderer" --header "Authorization: Bearer $APIFY_TOKEN"`. Or over stdio: `npx -y @apify/actors-mcp-server --tools fluidfaith/mermaid-chart-renderer` with `APIFY_TOKEN` set.

A good instruction for agents: *"When a diagram or chart would help, write it as Mermaid (or Vega-Lite for data), call mermaid-chart-renderer, and share fileUrl. If status is ERROR, fix the line in errorLine and call again."*

#### Through the API (one call, waits for the result)

```bash
curl -s -X POST "https://api.apify.com/v2/acts/fluidfaith~mermaid-chart-renderer/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"code":"sequenceDiagram\n  User->>Agent: question\n  Agent-->>User: diagram"}'
```

#### From JavaScript

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('fluidfaith/mermaid-chart-renderer').call({ code: 'pie title Pets\n  "Dogs" : 386\n  "Cats" : 85' });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0].status === 'OK' ? items[0].fileUrl : `${items[0].errorLine}: ${items[0].error}`);
```

### Pricing

Pay per event: **$0.003 per diagram rendered.** That is it: no start fee, nothing for errors, refused links or diagrams that hit the time limit. 100 diagrams cost $0.30. Set a maximum charge per run and the Actor stops before it, never after; the summary then shows `stoppedAtSpendingCap: true` and how many were not rendered.

### Safety

- Rendering is offline: the browser that draws the diagram cannot reach any network address, so code that points at outside images, data or internal addresses loads nothing. Vega-Lite specs that need outside data get a clear error instead of an empty chart.
- SVG input and every SVG output are cleaned: no scripts, no event handlers, no `javascript:` links, no embedded HTML.
- Mermaid runs with `securityLevel: strict` (no click handlers or HTML labels).
- `sourceUrl` only fetches public addresses: localhost, private networks, link-local and cloud metadata addresses are refused, including through redirects and DNS.

### Privacy

Your code and the files it produces stay in your own Apify run storage. Nothing is sent anywhere else, and no personal data is collected.

### FAQ

**Which Mermaid diagrams work?** Mermaid 12: flowchart, sequence, class, state, ER, gantt, pie, mindmap, timeline, journey, git graph, quadrant, sankey, XY chart, block, packet, kanban, architecture and more.

**Why did my Mermaid fail with "got 'participant_actor'"?** `Actor` is a Mermaid keyword in sequence diagrams. Rename the participant (for example `Renderer`). Errors like this are free; fix and retry.

**Can I use data from a URL in Vega-Lite?** Not inside the spec (rendering is offline). Put the rows under `data.values`, or fetch the whole spec with `sourceUrl`.

**How long are the files kept?** In your run's key-value store, for as long as your Apify plan keeps run storage (named storages keep them forever).

**Can I get a transparent PNG?** Yes: `"background": "transparent"`.

### Other Actors by Fluid Faith

- [Visual Regression & Screenshot Diff for AI Agents](https://apify.com/fluidfaith/visual-diff-gate): production vs preview, percent changed, changed regions and PASS or FAIL per viewport. $0.005 per page pair per viewport.
- [Mobile Website Test on iPhone & Android (Mobile QA Gate)](https://apify.com/fluidfaith/mobile-qa-gate): PASS or FAIL per page on today's phones, with screenshots. $0.01 per page per phone.
- [Lighthouse & Accessibility Audit](https://apify.com/fluidfaith/lighthouse-gate): Lighthouse scores, Core Web Vitals and axe-core issues with the top 5 fixes. $0.02 per URL per form factor.
- [PDF to Markdown with Tables](https://apify.com/fluidfaith/pdf-to-markdown-tables): PDF, Word, PowerPoint and Excel to Markdown with every table as JSON rows. $0.002 per page.
- [Video Frame Extractor & Media Probe](https://apify.com/fluidfaith/media-probe): ffprobe metadata, frames, scene cuts, a contact sheet and loudness from direct video or audio links. $0.001 per frame.

Load them together as MCP tools: `https://mcp.apify.com/?tools=fluidfaith/mermaid-chart-renderer,fluidfaith/visual-diff-gate,fluidfaith/mobile-qa-gate,fluidfaith/lighthouse-gate,fluidfaith/pdf-to-markdown-tables,fluidfaith/media-probe`

# Actor input Schema

## `code` (type: `string`):

The code of one diagram: Mermaid (flowchart, sequence, class, ER, gantt, pie, mindmap, timeline and more), Graphviz DOT, a Vega-Lite or Vega JSON spec, a Chart.js JSON config, or an <svg> element. Up to 200,000 characters.

## `type` (type: `string`):

What the code is. Leave empty to detect it: <svg> is SVG, digraph/graph is Graphviz, JSON with a vega-lite $schema is Vega-Lite, JSON with type+data.datasets is Chart.js, anything else is Mermaid.

## `diagrams` (type: `array`):

List of {"code": "...", "type": optional, "name": optional, "format": optional, "theme": optional, "sourceUrl": optional}. Up to 100 per run; each one is billed only if it renders. "sourceUrl" fetches the code from a public link (raw file, GitHub blob or gist link) instead of "code".

## `sourceUrl` (type: `string`):

Fetch the diagram code from a public link (a raw .mmd, .dot or .json file, a GitHub file page or a gist) instead of pasting it. Up to 1 MB. Private and internal addresses are refused.

## `name` (type: `string`):

Label for the single diagram; also used in the file name.

## `format` (type: `string`):

PNG for chat, Slack, email and docs; SVG for a scalable vector (the markup is also returned inline when under 100 KB); PDF for print. Chart.js gives PNG or PDF.

## `theme` (type: `string`):

Mermaid theme. "dark" also gives Vega-Lite and Chart.js light text on a dark background.

## `background` (type: `string`):

CSS color, for example white (the default), transparent, #0f172a. Dark theme defaults to #1e1e1e.

## `scale` (type: `integer`):

Pixel density of PNG output: 2 gives sharp images on phones and retina screens.

## `width` (type: `integer`):

Canvas width for Chart.js charts (other types size themselves).

## `height` (type: `integer`):

Canvas height for Chart.js charts.

## `graphvizEngine` (type: `string`):

dot for hierarchies and flows, neato or fdp for networks, circo for circles.

## `includeSvgText` (type: `boolean`):

With SVG output, also put the SVG markup in the result row (when under 100 KB), so an agent can embed it without a second download.

## `timeoutSecsPerDiagram` (type: `integer`):

A diagram that takes longer becomes an ERROR row and is not charged.

## `maxConcurrency` (type: `integer`):

How many diagrams render at the same time.

## Actor input object example

```json
{
  "code": "flowchart LR\n    A[Agent writes Mermaid] --> B{Valid?}\n    B -- yes --> C[PNG link]\n    B -- no --> D[Error with line number]\n    D --> A",
  "format": "png",
  "theme": "default",
  "scale": 2,
  "width": 800,
  "height": 500,
  "graphvizEngine": "dot",
  "includeSvgText": true,
  "timeoutSecsPerDiagram": 20,
  "maxConcurrency": 2
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "code": `flowchart LR
    A[Agent writes Mermaid] --> B{Valid?}
    B -- yes --> C[PNG link]
    B -- no --> D[Error with line number]
    D --> A`
};

// Run the Actor and wait for it to finish
const run = await client.actor("fluidfaith/mermaid-chart-renderer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "code": """flowchart LR
    A[Agent writes Mermaid] --> B{Valid?}
    B -- yes --> C[PNG link]
    B -- no --> D[Error with line number]
    D --> A""" }

# Run the Actor and wait for it to finish
run = client.actor("fluidfaith/mermaid-chart-renderer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "code": "flowchart LR\\n    A[Agent writes Mermaid] --> B{Valid?}\\n    B -- yes --> C[PNG link]\\n    B -- no --> D[Error with line number]\\n    D --> A"
}' |
apify call fluidfaith/mermaid-chart-renderer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fluidfaith/mermaid-chart-renderer"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/WZQ9MlAlMh3fsM3Xp/builds/dkoUhM1ijIp2NeOnp/openapi.json
