Chart API
Generate SVG charts with a simple GET request, or send the same options as JSON with POST. All customization parameters are optional.
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.
- GET: all options in the URL. Good for simple requests and <img src> links.
- POST: the same options as a JSON body. Good when you have many groups, labels, names or CSS and the URL would get too long.
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 -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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| type | string | ✅ | - | bar, line, pie, area, stacked-bar, donut, scatter, radar |
| data | string | ✅ | - | Comma-separated values (max 100). For scatter: JSON array of {"x":..., "y":...} |
| data2 - data5 | string | No | - | 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. |
| names | string | No | - | 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). |
| legend | boolean | No | automatic | Omit 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. |
| labels | string | No | - | Comma-separated labels |
| title | string | No | - | Chart title |
| apikey | string | ✅ | - | Your API key |
Customization Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| pointStyle | string | circle | circle, square, star, emoji, none |
| pointEmoji | string | ● | Any emoji (when pointStyle=emoji) |
| pointSize | number | 4 | Point size in pixels (2-10) |
| borderRadius | number | 0 | Corner rounding for the chart area (0-32) |
| lineWidth | number | 2 | Stroke width for lines (1-5) |
| bgStyle | string | none | Background effect: none, dots, grid, snow |
| bg | string | #FFFFFF | Chart background: a hex color (with or without #), or transparent. Built into the chart itself, no CSS needed |
| bg2 | string | - | Second hex color: makes the background a top-to-bottom gradient from bg to bg2 |
| bgOpacity | number | 1 | Background opacity from 0 (invisible) to 1 (solid). Affects only the background, not the chart content |
| bgStyleColor | string | #94A3B8 | Hex color of the bgStyle pattern (dots, grid, snow) |
| colors | string | - | Comma-separated hex colors, with or without # (up to 20). Cycles when fewer colors than items. Overrides the theme palette |
| theme | string | - | Ready-made color theme: pastel, vivid, warm, cool, ocean, sunset, forest, mono, retro, dark. Explicit colors override the theme palette |
| showValues | boolean | true | Show/hide data values on chart |
| customCSS | string | - | Custom CSS injected into the SVG (use with caution) |
Response Format
Unless save=true is used, the API returns an SVG image with the following 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.
/chart?type=bar&data=10,20,30&save=true&apikey=YOUR_KEY
Response (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).
/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).
/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.
/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
Code Examples
Copy and paste the code below to get started quickly in your preferred language.
JavaScript (Fetch)
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)
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 -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)
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
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_TYPE | Unknown chart type |
| 400 | INVALID_DATA | Malformed data |
| 401 | UNAUTHORIZED | Missing or invalid API key |
| 403 | DOMAIN_NOT_ALLOWED | API key restricted to specific domains |
| 403 | INVALID_SIGNATURE | Request signature verification failed |
| 403 | FORBIDDEN | Request blocked (e.g., restricted key usage) |
| 403 | ACCOUNT_SUSPENDED | Account has been suspended |
| 429 | RATE_LIMITED | Too many requests |
| 429 | QUOTA_EXCEEDED | Points quota exhausted (includes Retry-After header) |
| 500 | INTERNAL_ERROR | Internal server error |
| 503 | SERVICE_UNAVAILABLE | Chart generation service down |
Example
/chart?type=bar&data=45,52,38,65&labels=Q1,Q2,Q3,Q4&apikey=YOUR_KEY