API Documentation
Learn how to integrate Chart API into your application
Authentication
All API requests require authentication using a CLIENT-API-KEY header:
CLIENT-API-KEY: YOUR_CLIENT_API_KEY
Endpoint
POST
https://chartapi.pdfmunk.com/api/v1/generateChart
Request Body
Parameters
- chart_type
- Type of chart (e.g., "line", "bar", "pie") (required)
- data
- Chart data configuration (required)
- options
- Chart options and styling (optional)
- width
- Chart width in pixels (default: 800)
- height
- Chart height in pixels (default: 600)
- output_format
- Output format: "png" or "pdf" (default: "png")
Example Request
{
"chart_type": "line",
"data": {
"labels": ["Jan", "Feb", "Mar", "Apr", "May"],
"datasets": [{
"label": "Sales 2024",
"data": [12, 19, 3, 5, 2],
"borderColor": "rgb(75, 192, 192)",
"tension": 0.1
}]
},
"options": {
"responsive": true,
"plugins": {
"title": {
"display": true,
"text": "Monthly Sales"
}
}
},
"width": 800,
"height": 600,
"output_format": "png"
}
Try It Out
Please sign in to test the API.
Code Examples
Python
import requests
import json
CLIENT_API_KEY = 'your_client_api_key'
API_URL = 'https://chartapi.pdfmunk.com/api/v1/generateChart'
chart_config = {
"chart_type": "line",
"data": {
"labels": ["Jan", "Feb", "Mar", "Apr", "May"],
"datasets": [{
"label": "Sales 2024",
"data": [12, 19, 3, 5, 2],
"borderColor": "rgb(75, 192, 192)",
"tension": 0.1
}]
},
"options": {
"responsive": true,
"plugins": {
"title": {
"display": true,
"text": "Monthly Sales"
}
}
},
"width": 800,
"height": 600,
"output_format": "pdf"
}
response = requests.post(
API_URL,
headers={
'CLIENT-API-KEY': CLIENT_API_KEY,
'Content-Type': 'application/json'
},
json=chart_config
)
if response.ok:
# Save the chart
with open('chart.pdf', 'wb') as f:
f.write(response.content)
else:
print('Error:', response.json())
JavaScript
const CLIENT_API_KEY = 'your_client_api_key';
const API_URL = 'https://chartapi.pdfmunk.com/api/v1/generateChart';
const chartConfig = {
chart_type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
datasets: [{
label: 'Sales 2024',
data: [12, 19, 3, 5, 2],
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
},
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'Monthly Sales'
}
}
},
width: 800,
height: 600,
output_format: 'pdf'
};
fetch(API_URL, {
method: 'POST',
headers: {
'CLIENT-API-KEY': CLIENT_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify(chartConfig)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.blob();
})
.then(blob => {
// Create a URL for the blob
const url = window.URL.createObjectURL(blob);
// Create a link element and trigger download
const a = document.createElement('a');
a.href = url;
a.download = 'chart.pdf';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(error => console.error('Error:', error));
Error Codes
Code | Description |
---|---|
400 | Invalid request body or parameters |
401 | Invalid or missing API key |
429 | Rate limit exceeded |
500 | Internal server error |