Chart
The /chart endpoint generates charts from data. It supports bar, line, pie, and donut chart types, and returns either an SVG image or raw JSON data.
curl -X POST \ "https://api.moxon.dev/v6/chart" \ -H "Content-Type: application/json" \ -d '{}'Send the request to see the response here.
The request body must be JSON:
typestringrequiredChart type:
bar,line,pie, ordonut- bar
- line
- pie
- donut
datajsonrequiredChart data object (see structure below)
titlestringoptionalChart title displayed above the chart
widthnumberoptionalSVG width in pixels (responsive if omitted)
heightnumberoptionalSVG height in pixels (responsive if omitted)
colorsstringoptionalArray of hex colors for datasets (defaults to a built-in palette)
bgstringoptionalBackground fill color (hex, transparent if omitted)
legendbooleanoptionalShow legend:
true(default) orfalsemode"svg" | "data"optionalResponse format:
"svg"(default, returns SVG) or"data"(returns JSON)
data must be a JSON object (not a string) in the request body. The structure depends on the chart type.
Bar and line charts:
{
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{ "label": "Sales", "values": [120, 200, 150] },
{ "label": "Costs", "values": [80, 95, 110] }
]
}Pie and donut charts:
{
"labels": ["Jan", "Feb", "Mar"],
"values": [120, 200, 150]
}labels: array of strings — max 20 labelsdatasets(bar/line): array of dataset objects — max 5 datasets, each with alabeland avaluesarray matching the length oflabelsvalues(pie/donut): single array of non-negative numbers matching the length oflabels
The
datafield must be a JSON object, not a JSON string. Send the request withContent-Type: application/json.
- When
modeis"svg"(default): returnsContent-Type: image/svg+xmlwith the SVG body - When
modeis"data": returns a JSON object with the chart data
If parameters are missing or invalid, the API will return an error:
- 400
Please provide a valid chart type (?type=bar|line|pie|donut)Thetypeparameter is missing or invalid - 400
data must contain a labels arrayThedata.labelsfield is missing - 400
data must contain a datasets arrayThedata.datasetsfield is missing - 400
Too many labels (max 20)The labels array exceeds 20 entries - 400
Too many datasets (max 5)The datasets array exceeds 5 entries - 400
Each dataset must have the same number of values as labelsDataset length mismatch
Last updated on September 12, 2026