Chart API

Generate SVG charts with a simple GET request, or send the same options as JSON with POST. All customization parameters are optional.

💡 Note: The example images below are static samples of real API output. In your own requests, use your own key (shown as YOUR_KEY). Create one in the Dashboard.
GET
GET /chart?type={type}&data={data}&apikey={key}

GET or POST

/chart accepts both GET and POST. You choose which one to use. They give the same chart, use the same validation, the same points and return the same errors. Nothing converts one into the other.

The body fields have the same names as the GET parameters. Lists can be JSON arrays or the same comma-separated text GET uses. Send the API key in the Authorization: Bearer header or the apikey query parameter, not in the body. The body must be JSON (Content-Type: application/json) and at most 200,000 characters. Fields the API does not know are ignored, as in GET. If the same field is in both the URL and the body with different values, the request is rejected with INVALID_DATA; nothing is charged. Labels and names cannot contain a comma in either method.

cURL (POST)
curl -X POST "https://api.divct.workers.dev/chart" \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"bar","data":[45,52,38,65],"data2":[30,40,35,50],"names":["Sales","Costs"],"labels":["Q1","Q2","Q3","Q4"]}' \
  -o chart.svg

This returns exactly the same SVG as the GET request with the same options. With save: true in the body (or save=true in the URL) you get the saved-chart JSON, as in GET.

Core Parameters

ParameterTypeRequiredDefaultDescription
typestring✅-bar, line, pie, area, stacked-bar, donut, scatter, radar
datastring✅-Comma-separated values (max 100). For scatter: JSON array of {"x":..., "y":...}
data2 - data5stringNo-Additional groups (up to 5 total) for bar, stacked-bar, line, area, scatter and radar. Pie and donut accept one group only (an error is returned). Bar and stacked-bar need the same number of values in every group; radar needs one value per label in every group. Each value in every group counts as one point.
namesstringNo-Comma-separated group names for the legend, in order data, data2 to data5. Missing names show as "Series 1", "Series 2". Max 60 characters each, no commas inside a name. Not for pie and donut (use labels).
legendbooleanNoautomaticOmit it: the legend shows when there are 2+ groups (pie and donut: when labels are given). true always shows it, even for one group. false hides it. Any other value returns INVALID_DATA. A legend makes the image about 38 px taller and costs no points.
labelsstringNo-Comma-separated labels
titlestringNo-Chart title
apikeystring✅-Your API key
💡 Note: For scatter charts, the data parameter must be a JSON array of objects, e.g. [{"x":10,"y":20},{"x":25,"y":45}].

Customization Parameters

ParameterTypeDefaultDescription
pointStylestringcirclecircle, square, star, emoji, none
pointEmojistring●Any emoji (when pointStyle=emoji)
pointSizenumber4Point size in pixels (2-10)
borderRadiusnumber0Corner rounding for the chart area (0-32)
lineWidthnumber2Stroke width for lines (1-5)
bgStylestringnoneBackground effect: none, dots, grid, snow
bgstring#FFFFFFChart background: a hex color (with or without #), or transparent. Built into the chart itself, no CSS needed
bg2string-Second hex color: makes the background a top-to-bottom gradient from bg to bg2
bgOpacitynumber1Background opacity from 0 (invisible) to 1 (solid). Affects only the background, not the chart content
bgStyleColorstring#94A3B8Hex color of the bgStyle pattern (dots, grid, snow)
colorsstring-Comma-separated hex colors, with or without # (up to 20). Cycles when fewer colors than items. Overrides the theme palette
themestring-Ready-made color theme: pastel, vivid, warm, cool, ocean, sunset, forest, mono, retro, dark. Explicit colors override the theme palette
showValuesbooleantrueShow/hide data values on chart
customCSSstring-Custom CSS injected into the SVG (use with caution)
⚠️ Security Warning: The customCSS parameter allows injecting CSS into the SVG. Only use it with trusted input, as it may lead to unintended behavior.

Response Format

Unless save=true is used, the API returns an SVG image with the following headers:

Headers
Content-Type: image/svg+xml
Cache-Control: public, max-age=60
Access-Control-Allow-Origin: *

Save & Share

Add save=true to save the chart and get a URL that stays valid until expires_at (30 or 60 days). The API returns JSON (not SVG) when save=true.

GET
/chart?type=bar&data=10,20,30&save=true&apikey=YOUR_KEY

Response (JSON):

JSON
{
  "saved": true,
  "url": "https://api.divct.workers.dev/saved/a1b2c3d4-...",
  "expires_at": "2026-12-01T00:00:00.000Z",
  "expires_in_days": 30
}

You can customize the expiry duration using expiryDays=60 (allowed values: 30 or 60).

GET
/chart?type=bar&data=10,20,30&save=true&expiryDays=60&apikey=YOUR_KEY

Multiple Datasets

Use data2, data3, data4, data5 to add up to 5 datasets (for grouped or stacked charts).

GET
/chart?type=bar&data=45,52,38,65&data2=30,40,35,50&data3=20,25,18,30&labels=Q1,Q2,Q3,Q4&apikey=YOUR_KEY

Group Names and Legend

Name each group with names. The chart then shows a legend with each group's color and name. With two or more groups the legend appears on its own; add legend=false to hide it, or legend=true to show it for a single group. Long names wrap to a second line. For pie and donut the legend lists the slices from labels.

GET
/chart?type=bar&data=45,52,38,65&data2=30,40,35,50&data3=20,25,18,30&names=Sales,Costs,Profit&labels=Q1,Q2,Q3,Q4&apikey=YOUR_KEY
Grouped bar chart with a legend: Sales, Costs, Profit

Code Examples

Copy and paste the code below to get started quickly in your preferred language.

JavaScript (Fetch)
JavaScript
const apiKey = 'YOUR_KEY';
const url = `https://api.divct.workers.dev/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey=${apiKey}`;

fetch(url)
  .then(res => res.text())
  .then(svg => {
    document.getElementById('chart-container').innerHTML = svg;
  })
  .catch(err => console.error(err));
Python (Requests)
Python
import requests

api_key = "YOUR_KEY"
url = f"https://api.divct.workers.dev/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey={api_key}"

response = requests.get(url)
if response.status_code == 200:
    with open("chart.svg", "wb") as f:
        f.write(response.content)
    print("Chart saved as chart.svg")
else:
    print("Error:", response.json())
cURL (Command Line)
cURL
curl -o chart.svg "https://api.divct.workers.dev/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey=YOUR_KEY"
Node.js (Axios)
Node.js
const axios = require('axios');
const fs = require('fs');

const apiKey = 'YOUR_KEY';
const url = `https://api.divct.workers.dev/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey=${apiKey}`;

axios.get(url, { responseType: 'text' })
  .then(res => {
    fs.writeFileSync('chart.svg', res.data);
    console.log('Chart saved as chart.svg');
  })
  .catch(err => console.error(err));

Error Codes

StatusCodeDescription
400INVALID_TYPEUnknown chart type
400INVALID_DATAMalformed data
401UNAUTHORIZEDMissing or invalid API key
403DOMAIN_NOT_ALLOWEDAPI key restricted to specific domains
403INVALID_SIGNATURERequest signature verification failed
403FORBIDDENRequest blocked (e.g., restricted key usage)
403ACCOUNT_SUSPENDEDAccount has been suspended
429RATE_LIMITEDToo many requests
429QUOTA_EXCEEDEDPoints quota exhausted (includes Retry-After header)
500INTERNAL_ERRORInternal server error
503SERVICE_UNAVAILABLEChart generation service down

Example

GET
/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey=YOUR_KEY
Resultbar
Bar Chart

Next Steps

📊 Chart Types

Explore all 8 chart types with examples.

Explore →
🎨 Customization

Learn about styling parameters (pointStyle, bgStyle, etc.).

Customize →
🔀 Graph API

Generate flowcharts with nodes and links.

View Graph API →