Draw Charts from an Agent
An agent draws a chart by emitting a fenced code block tagged chart whose body is strict JSON that follows the Agentic Data Plane chart contract.
The Playground renders the data with the Agentic Data Plane chart components.
The fence body contains data, not Recharts component code.
The agent’s Playground tab renders that block with Chart, Data, and Code views.
This is a rendering convention: the agent decides when a chart helps and writes the data, and the Playground draws it.
No tool call or application setup is required.
|
The chart contract supports |
After reading this page, you will be able to:
-
Instruct an agent to draw a bar or line chart by emitting a chart code block
-
Migrate an earlier chart prompt to the Agentic Data Plane chart contract
-
Diagnose a chart that renders as an error or stays a placeholder
Prerequisites
-
A deployed agent in Agentic Data Plane. To create one, see Create an Agent.
-
An understanding of how to write an agent system prompt. See Write Effective System Prompts.
How chart rendering works
When the agent’s response contains a fenced code block tagged chart, the Playground parses the block body as a chart configuration and draws the chart in place of the code.
Every other code block renders as plain code, so a chart block is the agent’s only departure from ordinary output.
The renderer supplies the visual presentation. A valid configuration renders as a responsive SVG chart with the Redpanda theme, a tooltip, and a legend. The agent supplies the chart type, optional title, labels, series names, and numeric values.
Agentic Data Plane draws a chart block wherever it shows the agent’s response: the agent’s Playground tab and the Transcripts tab.
When an external application calls the agent, whether that application draws the chart depends on how it renders the agent’s output.
Write the chart block
Use the fields below. Unsupported chart types or invalid values show an error.
-
Tag the fence
chart. The opening fence is three backticks followed by the wordchart, with no other language tag. -
Write the body as strict JSON. The Playground parses the body with a JSON parser, not a JavaScript evaluator, so use double-quoted keys and strings, unquoted numbers, no trailing commas, no comments, and no JavaScript expressions, functions, or callbacks.
-
Set the top-level
typetobarorline. -
Add a top-level
dataobject withlabelsanddatasetsarrays. Each dataset contains adataarray and can include alabel. Without alabel, the Playground names the seriesSeries 1,Series 2, and so on. Values in a dataset must be finite numbers ornull. -
To display a title, add a top-level
titlestring. -
Do not add renderer-specific
options, plugins, scales, animations, or color properties. The Playground controls those presentation details.
A bar chart:
```chart
{
"type": "bar",
"title": "Monthly orders",
"data": {
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{ "label": "Orders", "data": [120, 190, 140] }
]
}
}
```
Instruct the agent through its system prompt
To render a chart, tell the agent to emit a valid chart block.
Add the convention to the agent’s system prompt: name the fence tag, state the strict JSON rules, list the supported types, and include one worked example.
The following snippet works as a standalone prompt or as a section added to an existing one:
You can draw charts inline. When a bar or line chart communicates better than
text, emit one fenced code block tagged exactly `chart` whose body follows the
chart contract as strict JSON.
Rules for the chart block:
- The fence language tag is exactly: chart
- The body is valid JSON: double-quoted keys and strings, unquoted numbers,
no trailing commas, no comments, and no JavaScript, functions, or callbacks.
- The top level contains "type", optional "title", and "data".
- Allowed "type" values: "bar" and "line".
- "data" contains "labels" and "datasets". Each dataset contains a numeric
"data" array and can include a "label".
- Do not emit renderer-specific options, plugins, scales, animations, or colors.
- Put a brief plain-text explanation (1 or 2 sentences) before the chart block.
Do not also paste a data table; the Playground has a built-in Data view.
Example response to "show last quarter's orders by month":
Orders peaked in February:
```chart
{
"type": "bar",
"title": "Last quarter's orders",
"data": {
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{ "label": "Orders", "data": [120, 190, 140] }
]
}
}
```
For prompt-writing patterns that make this output reliable, see Output formatting.
Test the chart in the Playground
-
Open the agent and switch to the Playground tab.
-
Enter a prompt that calls for a chart, such as
Show the broker count for the demo cluster over the last 3 months as a bar chart. -
Wait for the agent to finish its response. The chart appears in place of the
chartblock.
Use the view selector to switch between:
-
Chart: The responsive bar or line chart. Hover over the chart to inspect values.
-
Data: The chart’s values as a table, reconstructed from the configuration.
-
Code: The JSON configuration the Playground parsed.
Zoom, pan, and PNG export are not available.
Migrate from Chart.js
Existing bar and line configurations keep their type, labels, datasets, and values.
Move the title to the top level and remove legacy presentation options.
Convert other chart types to bar or line.
| Earlier Chart.js configuration | Current chart contract |
|---|---|
|
Keep the type. |
|
Use |
|
Choose |
|
Move the string to the top-level |
|
Remove them. The Playground supplies the presentation. |
Zoom, pan, or PNG export instructions |
Remove them. These controls are not available. |
For example, replace:
{
"type": "bar",
"data": {
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{
"label": "Orders",
"data": [120, 190, 140],
"backgroundColor": "#ea580c"
}
]
},
"options": {
"plugins": {
"title": {
"display": true,
"text": "Monthly orders"
}
}
}
}
With:
{
"type": "bar",
"title": "Monthly orders",
"data": {
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{ "label": "Orders", "data": [120, 190, 140] }
]
}
}
Troubleshooting
A block that does not satisfy the contract shows an inline error that names the problem. Click Error details to inspect the body the agent sent.
| Symptom | Cause and fix |
|---|---|
A Failed to render chart error appears in place of the chart |
The block body does not satisfy the contract.
The error description names the problem. Click Error details to inspect the body the agent sent.
Common causes include invalid JSON, a missing |
The error description reads Unsupported chart type |
Change the type to |
A Building chart… placeholder remains visible |
The placeholder shows while the |
The agent pastes a table or raw JSON instead of a chart |
The agent either did not tag the fence |