← Back to blog

Generate Charts with One API Call: Bar, Line & Pie from Data

July 29, 2026 · Eric · 7 min read

You have data. You need a chart. No libraries, no headless browsers, no JavaScript build pipeline. One HTTP POST gets you an SVG or PNG you can embed, email, store, or pass to another tool.

The Chart Generation API at Agent Media Tools turns a JSON payload into a rendered chart image in a single request. It supports three chart types — bar, line, and pie — with custom titles, labels, output formats, and dimensions. No signup is required.

Quick Start: curl

The simplest possible example — three values, no labels:

curl -s https://agentmediatools.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{"values":[10,25,15,40,30]}' \
  | jq .

Response (truncated):

{
  "success": true,
  "filename": "a1b2c3d4-e5f6-7890-abcd-ef1234567890.svg",
  "downloadUrl": "/downloads/a1b2c3d4-e5f6-7890-abcd-ef1234567890.svg",
  "size": 2840,
  "type": "bar",
  "title": "Chart"
}

Passing no type defaults to bar, and the title defaults to "Chart". The response includes a downloadUrl you can fetch immediately — the file lives in ephemeral storage so save it when you need it.

Request Parameters

FieldTypeDefaultDescription
typestring"bar""bar", "line", or "pie"
valuesnumber[]requiredData points (up to 40)
labelsstring[]index numbersPer-point labels; auto-numbered if omitted
titlestring"Chart"Up to 80 characters
formatstring"svg""svg" or "png"
widthnumber800Canvas width in pixels
heightnumber480Canvas height in pixels

Only values is required. Everything else has sensible defaults, so you can go from zero to a chart in a single line of curl.

Chart Types

Bar Chart (default)

curl -s https://agentmediatools.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{
    "type": "bar",
    "title": "Monthly Revenue",
    "labels": ["Jan","Feb","Mar","Apr","May"],
    "values": [4200, 5800, 6300, 7100, 8400]
  }'

Each bar gets its own color from an eight-color palette. Labels render below the X axis. Values map linearly to bar height against a dark background with axes.

Line Chart

curl -s https://agentmediatools.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{
    "type": "line",
    "title": "CPU Utilization (24h)",
    "labels": ["0h","6h","12h","18h","24h"],
    "values": [45, 62, 78, 55, 38]
  }'

Line charts render a gold polyline with dot markers at each data point. Great for time-series, trends, and continuous metrics.

Pie Chart

curl -s https://agentmediatools.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{
    "type": "pie",
    "title": "Browser Market Share",
    "labels": ["Chrome","Safari","Firefox","Edge","Other"],
    "values": [65, 18, 8, 5, 4]
  }'

Pie charts compute proportional slices from your values. Labels are currently rendered only in bar mode, so for pie charts the legend is implied by the value order — keep it simple.

Getting PNG Instead of SVG

By default the API returns an SVG download URL. SVGs are tiny, editable, and scale infinitely — perfect for embedding in web pages or editing in design tools. If you need a raster image, pass "format": "png":

curl -s https://agentmediatools.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Export as PNG",
    "values": [10, 20, 30],
    "format": "png"
  }' | jq .

The server renders the SVG, converts it to PNG via Sharp, and returns a download URL pointing to the raster output. Choose PNG for email attachments, social cards, or any context that needs a flat image.

Python: requests Example

For scripts, automation, and data pipelines, Python's requests library is the natural choice:

import requests

resp = requests.post("https://agentmediatools.com/api/chart", json={
    "type": "bar",
    "title": "Q4 Performance",
    "labels": ["Oct", "Nov", "Dec"],
    "values": [88, 92, 97],
    "format": "png"
})
data = resp.json()

# Download the rendered chart
chart = requests.get(f"https://agentmediatools.com{data['downloadUrl']}")
with open("q4-chart.png", "wb") as f:
    f.write(chart.content)

print(f"Chart saved: q4-chart.png ({data['size']} bytes)")

That's the entire workflow — POST data, receive a URL, download the file. No client SDK, no auth token, no configuration file.

Batch Chart Generation

When you have multiple datasets to visualize, iterate:

import requests

datasets = [
    ("revenue", {"type": "bar", "title": "Revenue", "values": [12, 19, 25, 32]}),
    ("users",   {"type": "line", "title": "Active Users", "values": [450, 720, 1100, 1650]}),
    ("share",   {"type": "pie", "title": "Platform Share", "values": [40, 30, 20, 10]}),
]

API = "https://agentmediatools.com/api/chart"

for name, payload in datasets:
    r = requests.post(API, json=payload)
    url = f"https://agentmediatools.com{r.json()['downloadUrl']}"
    img = requests.get(url)
    with open(f"{name}.{payload.get('format', 'svg')}", "wb") as f:
        f.write(img.content)
    print(f"{name}.svg saved")

Each POST is independent — run them in a loop for a dashboard export or fan them out concurrently with ThreadPoolExecutor.

Use It from Any AI Agent (MCP)

If your agent uses the MCP server, the generate_chart tool is already registered. Agents that can call MCP tools — Claude Desktop, Cline, GoMCP, custom hosts — can produce charts without touching curl:

{
  "name": "generate_chart",
  "arguments": {
    "type": "bar",
    "title": "Agent Task Completion",
    "labels": ["Crawl", "Extract", "Summarize", "Deliver"],
    "values": [42, 38, 41, 40],
    "format": "png"
  }
}

The MCP tool returns the same JSON response the REST API does, including the download URL. Your agent can then fetch the image, show it in its UI, or pass it along to another tool in a pipeline.

Real-World Use Cases

Limits & Notes

Comparison: Chart API vs. Bundling a Library

ScenarioChart APIChart.js / D3
Time to first chart~3 seconds (one curl)15+ minutes (install, import, configure)
Server-side renderingBuilt-in (SVG + PNG)Need headless Chromium (Puppeteer/Playwright)
AI agent integrationOne function call (MCP)Not directly callable
Deploy-time dependencyZeronpm install, build pipeline
Offline capabilityRequires internetWorks offline

The chart API shines when you need a chart somewhere else — in an email, a document, a chat message, an agent response. If you're building an interactive client-side dashboard with real-time updates, Chart.js or D3 is the right tool. They solve different problems.

Try It Now

Go to the Agent Media Tools toolbox or run the curl command above. The chart endpoint needs no signup or credit card, and the wider toolbox offers additional browser, REST, and MCP tools when your workflow grows.

Try it in the Toolbox

Run the chart generator in the browser, or call it from your agent with an API key.

Open toolbox