# Chart image API

> Send chart data as JSON in a URL or a POST body to https://render.cuelark.com/v1/chart and get a PNG or SVG image back, cached at the edge.

URL: https://render.cuelark.com/chart-image-api

## Simplest call: a URL
```text
https://render.cuelark.com/v1/chart?type=bar&title=Signups&labels=Mon,Tue,Wed,Thu,Fri&data=12,19,8,15,22
```

## Full JSON in the URL
```text
https://render.cuelark.com/v1/chart?c={"type":"line","labels":["Q1","Q2","Q3"],"datasets":[{"label":"MRR","data":[4.1,5.3,6.8]}],"prefix":"$","suffix":"K"}
```

## POST from code
```bash
curl -X POST https://render.cuelark.com/v1/chart \
  -H "content-type: application/json" \
  -d '{"chart":{"type":"pie","labels":["Yes","No"],"datasets":[{"data":[61,39]}]},"format":"png","scale":2}' \
  -o chart.png
```

## Parameters
| Field | Values | Default |
|---|---|---|
| type | bar, horizontalBar, line, area, pie, doughnut | bar |
| labels / datasets | arrays (or Chart.js data, or shorthand data) | - |
| title, subtitle, xLabel, yLabel | text | - |
| stacked, showValues, legend | true / false | false, false, true |
| prefix, suffix | e.g. $ and % | - |
| theme | light, dark | light |
| width, height | 200-2000, 150-1500 px | 800 × 450 |
| format, scale | png or svg; 1-3 | png, 1 |

## Speed and caching
Charts are drawn in the Cloudflare Worker that answers the request, as SVG rasterized with resvg. There's no headless browser, so a fresh chart usually renders in tens of milliseconds and repeat GET URLs come from Cloudflare's cache.

## FAQ
### Is the chart API free?
Yes. Chart and social card images are free within a rate limit of 120 requests per minute per IP. Cached image URLs don't count against it.

### Do I need an API key?
Not today. Cuelark accounts with API keys are coming, and anonymous chart URLs will keep working.

### Can I embed the chart in an email?
Yes. Use the GET URL as an <img src>. Email clients fetch it like any other image.

### Is it a QuickChart alternative?
For static bar, line, pie and doughnut charts, yes. It reads Chart.js-style JSON. It doesn't run Chart.js plugins or JavaScript callbacks.
