Skip to content
chartqueryPublic

About

Chart API by ChartQuery: Render Chart.js charts as images — or describe them in plain English. Python, TypeScript, cURL, PHP, C#, Go, Java, Ruby examples.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chart API by ChartQuery

Chart API

Discord Get API key API docs License: MIT

The ChartQuery Chart API renders a Chart.js configuration as an image, or generates a chart from a plain-English prompt with AI.

  • Chart Render API — Render a Chart.js image via GET.
  • AI Chart API — Describe a chart in plain English via GET and get a rendered image back.

Use it for charts in emails, PDF reports, Slack bots, dashboards and AI assistants.

Endpoint Request Credits
Chart Render API GET /v1/chart 5
AI Chart API GET /v1/chart/ai 10

Table of contents

How it works

  1. Create a ChartQuery account and copy your API key from the dashboard.
  2. Call https://api.chartquery.com with the header x-api-key: YOUR_API_KEY.
  3. Use the result in your app — no infrastructure to run.
export CHARTQUERY_API_KEY="your-api-key"
pip install requests        # Python
# TypeScript: Node.js 18+ (native fetch), run with `npx tsx file.ts`

Chart Render API

Render a Chart.js image via GET. Pass the full chart object as URL-encoded JSON in query. Prefer format png for ChatGPT. POST sends the same object as a JSON body, not query.

GET https://api.chartquery.com/v1/chart · 5 credits per request · API reference

Request parameters

Parameter In Type Required Description
query query string ✅ Full chart config as JSON. The playground sends it as the query parameter.
version query string — Chart.js version to render with. Default: 4.5.1. Only v4 is supported.
share query boolean — Persist the result and return share URLs instead of the image.

Python example

import os

import requests

API_KEY = os.environ["CHARTQUERY_API_KEY"]
HEADERS = {"x-api-key": API_KEY}

response = requests.get(
    "https://api.chartquery.com/v1/chart",
    headers=HEADERS,
    params={
        "query": "{\"type\":\"bar\",\"title\":\"Monthly Sales\",\"legend\":\"bottom\",\"width\":1200,\"height\":600,\"device_pixel_ratio\":1,\"data\":{\"labels\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\"],\"datasets\":[{\"label\":\"2025\",\"data\":[42,58,37,65,49,72],\"backgroundColor\":\"rgba(99,102,241,0.85)\"},{\"label\":\"2026\",\"data\":[51,67,44,71,58,85],\"backgroundColor\":\"rgba(249,115,22,0.85)\"}]},\"scales\":{\"y\":{\"beginAtZero\":true}}}",
    },
    timeout=120,
)
response.raise_for_status()

with open("chart.png", "wb") as f:
    f.write(response.content)
print("Saved chart.png", len(response.content), "bytes")

TypeScript example

import { writeFile } from "node:fs/promises";

const headers = { "x-api-key": process.env.CHARTQUERY_API_KEY!, "Content-Type": "application/json" };

const params = new URLSearchParams({
  "query": "{\"type\":\"bar\",\"title\":\"Monthly Sales\",\"legend\":\"bottom\",\"width\":1200,\"height\":600,\"device_pixel_ratio\":1,\"data\":{\"labels\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\"],\"datasets\":[{\"label\":\"2025\",\"data\":[42,58,37,65,49,72],\"backgroundColor\":\"rgba(99,102,241,0.85)\"},{\"label\":\"2026\",\"data\":[51,67,44,71,58,85],\"backgroundColor\":\"rgba(249,115,22,0.85)\"}]},\"scales\":{\"y\":{\"beginAtZero\":true}}}",
});

const response = await fetch(`https://api.chartquery.com/v1/chart?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);

await writeFile("chart.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved chart.png");

Output

The response body is the generated file (saved as chart.png in every example). Error responses are JSON with an explanatory message.

AI Chart API

Describe a chart in plain English via GET and get a rendered image back. Powered by AI.

GET https://api.chartquery.com/v1/chart/ai · 10 credits per request · API reference

Request parameters

Parameter In Type Required Description
prompt query string ✅ Describe the chart in plain language. 5 to 1000 characters. Name the chart type, the subject, and the colors.
raw_data query string — Data the model should plot. A string, a JSON array, or a JSON object. Limit: 10 000 characters or 500 items.
title query string — Chart title. On the AI endpoints this replaces the generated title.
subtitle query string — Chart subtitle. On the AI endpoints this replaces the generated subtitle.
legend query string (top, bottom, left, right, chartArea, false) — Legend position, or hide it.
format query string (png, svg) — Output format. Default: png.
width query number — Width of the image, in pixels, from 50 to 4000. Default: 1200.
height query number — Height of the image, in pixels, from 50 to 4000. Default: 600.
background query string — Background color. Default: #ffffff.
device_pixel_ratio query number — Device pixel ratio of the render. Default: 1.
share query boolean — Persist the result and return share URLs instead of the image.

Python example

import os

import requests

API_KEY = os.environ["CHARTQUERY_API_KEY"]
HEADERS = {"x-api-key": API_KEY}

response = requests.get(
    "https://api.chartquery.com/v1/chart/ai",
    headers=HEADERS,
    params={
        "prompt": "Bar chart of monthly sales from January to June, indigo bars, clean style",
        "format": "png",
    },
    timeout=120,
)
response.raise_for_status()

with open("ai-chart.png", "wb") as f:
    f.write(response.content)
print("Saved ai-chart.png", len(response.content), "bytes")

TypeScript example

import { writeFile } from "node:fs/promises";

const headers = { "x-api-key": process.env.CHARTQUERY_API_KEY!, "Content-Type": "application/json" };

const params = new URLSearchParams({
  "prompt": "Bar chart of monthly sales from January to June, indigo bars, clean style",
  "format": "png",
});

const response = await fetch(`https://api.chartquery.com/v1/chart/ai?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);

await writeFile("ai-chart.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved ai-chart.png");

Output

The response body is the generated file (saved as ai-chart.png in every example). Error responses are JSON with an explanatory message.

Code examples in other languages

Ready-to-run examples live in examples/; each reads your key from CHARTQUERY_API_KEY.

Language chart chart-ai
cURL (Bash) chart.sh chart_ai.sh
PHP chart.php chart_ai.php
C# Chart.cs ChartAi.cs
Go chart.go chart_ai.go
Java ChartExample.java ChartAiExample.java
Ruby chart.rb chart_ai.rb
Node.js chart.mjs chart_ai.mjs

Use cases

  • Email & PDF reports — Embed charts where JavaScript can't run.
  • Chatbots & AI agents — Return charts as images from Slack, Discord or ChatGPT tools.
  • Automated reporting — Generate weekly KPI charts from your data pipeline.

Why ChartQuery?

  • Images in one request — the response body is the PNG/SVG/PDF, ready for emails, PDFs, dashboards, Slack or <img> tags.
  • Charts, diagrams, QR codes, barcodes, labels — Chart.js configs, 28 diagram languages (Mermaid, Graphviz, PlantUML, D2…), 25+ barcode formats.
  • AI generation — describe a chart or diagram in plain English and get the rendered image.
  • No rendering infrastructure — no headless browser, fonts or libraries to maintain.
  • Copy-paste examples — Python and TypeScript in each README, 7 more languages in examples/.

FAQ

How do I authenticate?

Create an account on ChartQuery, copy your API key and send it in the x-api-key header of every request to https://api.chartquery.com.

How much does a request cost?

Credits per call: /v1/chart 5, /v1/chart/ai 10. See ChartQuery pricing.

What does the API return?

The response body is the file itself (image or document). Save it directly to disk or stream it to your storage — every example in this repository writes the file locally.

Which languages are supported?

Any language that can make an HTTP request. This README shows Python and TypeScript; the examples/ folder contains cURL, PHP, C#, Go, Java, Ruby and Node.js.

Official SDKs

Use ChartQuery from your own language with a typed client:

SDK Package Install
Node.js @chartquery/sdk npm install @chartquery/sdk
Python chartquery pip install chartquery
Go chartquery-go go get github.com/chartquery/chartquery-go
.NET ChartQuery dotnet add package ChartQuery
Ruby chartquery gem install chartquery
PHP chartquery/sdk composer require chartquery/sdk
Java chartquery-java build from source, see its README
CLI @chartquery/cli npm install -g @chartquery/cli
MCP server @chartquery/mcp npx -y @chartquery/mcp

Related repositories

Support


ChartQuery
Built by ChartQuery. Examples are released under the MIT license.

About

Chart API by ChartQuery: Render Chart.js charts as images — or describe them in plain English. Python, TypeScript, cURL, PHP, C#, Go, Java, Ruby examples.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors