Chart definitions
A chart definition describes a chart as a small JSON object: which data to read, which fields go where, and how it should look. AI agents
write it, apps save it, and the same definition draws with <RioChart Definition="..." />, on the server, or through
the create_chart tool.
This page explains the format, one idea at a time, with each definition next to the chart it draws. At the end you can try it yourself. To let people build charts without writing JSON, see the chart editor.
A first definition
A definition names a dataset and, for each series, the fields (columns) that go along the x axis and up the y axis. Everything else has a default. This one sums the revenue per month and draws it as a line.
Revenue per month
Code
{
"dataset": "sales",
"series": [{ "type": "line", "x": "month", "y": "revenue", "aggregate": "sum" }]
}Data: datasets and fields
The definition holds no data itself. Your app passes in named datasets, tables with one value per row for each field, and the definition refers to them by name. Field types (time, number, text) are read from the values. Because only names travel, a definition is small, safe to save, and never contains anyone's data. These are the datasets the examples on this page read:
Online store traffic per sales channel (Web, App, Marketplace), hourly for one week. Passed in from C# with Datasets="datasets".
504 rows, 6 fields
timestamp time | channel text | sessions number | orders number | revenue number | responseMs number |
|---|---|---|---|---|---|
| 2026-11-14 00:00 | Web | 778 | 18 | 1283 | 175 |
| 2026-11-18 04:00 | Web | 298 | 7 | 577 | 165 |
| 2026-11-15 09:00 | App | 89 | 2 | 166 | 131 |
| 2026-11-19 14:00 | App | 367 | 9 | 742 | 154 |
| 2026-11-16 19:00 | Marketplace | 352 | 8 | 651 | 169 |
5 of 504 rows, spread over the dataset.
A small definition can also carry its own rows in "data" (at most 1000), for a few values an
agent already has. How your app builds datasets is under where the data comes from.
Chart types
type picks the chart. Most read x and y; some read more fields, such as a range bar's
start and end. With auto, the chart picks a type from the data: time along x gives a line,
categories give bars, and shares that add up to 100 give a donut. Common names from other libraries are accepted too:
column, doughnut, spline, stackedBar.
| Type | What it reads |
|---|---|
line, area, bar | x (time, number or category) and y. A stack name stacks series; "horizontal": true on the chart lays bars sideways. |
pie, funnel, radialBar | x names the slice or stage, y its size. innerRadius makes a donut. |
scatter | Two numbers, x and y; a size field makes bubbles. |
heatmap, calendar | A heatmap: x columns, groupBy rows, y the color. A calendar: a time x, one square per day. |
histogram, boxPlot | How values spread: a histogram counts a number field in bins; a box plot shows each group's quartiles. |
rangeBar, dumbbell, rangeArea | From–to values: a timeline's row, start and end; a dumbbell's from and y; a band's low and y. |
waterfall, candlestick | Steps that add up (with total rows), and prices with open, high, low and y as the close. |
gauge, bullet | One value against a scale (min, max, target), or a value per row against its targetField. |
treemap, radar, map, mapBubble | Nested groups (path), spokes, countries, and places by latitude and longitude. |
Shaping the data
A series can reshape its rows before it draws, so the data can stay as it is stored:
filterkeeps the rows that match all conditions:[{ "field": "channel", "op": "eq", "value": "App" }], with eq, ne, gt, gte, lt, lte and contains.timeBucketgroups a time x per minute, hour, day, week, month, quarter or year (orauto), andaggregatecombines the rows in each group or category: sum, average, min, max, count or last.groupBymakes one series per value of a field: one line per sales channel.sortranks the categories by value, andlimitkeeps the first N: a top 10.
Revenue per day and channel
Hourly rows grouped per day, summed, one series per channel, stacked.
Code
{
"dataset": "shop",
"y": { "title": "€" },
"series": [{ "type": "bar", "x": "timestamp", "y": "revenue", "timeBucket": "day", "aggregate": "sum",
"groupBy": "channel", "stack": "channels", "format": "#,0 €" }]
}Top three categories
Monthly rows summed per category, sorted, the top three kept, laid sideways.
Code
{
"dataset": "sales",
"horizontal": true,
"series": [{ "type": "bar", "x": "category", "y": "revenue", "aggregate": "sum",
"sort": "descending", "limit": 3, "format": "0 k€" }]
}Axes, legend and annotations
The rest is the same model as the Blazor components: axis titles, formats and ranges (x, y and more vertical
axes in yAxes), the legend, the tooltip, reference lines and bands in annotations, and the
chart's timeZone. A series picks its axis with yAxisId.
Two axes and a goal line
Code
{
"dataset": "shop",
"y": { "title": "Sessions" },
"yAxes": [{ "id": "eur", "title": "€" }],
"series": [
{ "type": "bar", "x": "timestamp", "y": "revenue", "timeBucket": "day", "aggregate": "sum", "yAxisId": "eur", "name": "Revenue" },
{ "type": "line", "x": "timestamp", "y": "sessions", "timeBucket": "day", "aggregate": "sum", "name": "Sessions" }
],
"annotations": [{ "value": 7000, "label": "Goal: 7,000 sessions" }]
}Errors that say what to do
A definition is checked when it is read and again when it meets the data. Each error names the path to the problem and what is valid, so
a person or an agent can fix it and try again. Small slips are read anyway, with a warning: "timeBucket": "daily" means day,
"type": "column" means bar. Here the field names are wrong:
A definition with errors
series[0].xfield 'time' not found in 'shop'; available: timestamp (time), channel (text), sessions (number), orders (number), revenue (number), responseMs (number).series[0].yfield 'visits' not found in 'shop'; available: timestamp (time), channel (text), sessions (number), orders (number), revenue (number), responseMs (number).
Code
{
"dataset": "shop",
"series": [{ "type": "line", "x": "time", "y": "visits" }]
}Saved definitions keep working
A definition can say which format it is in: "version": 1. It is optional (missing means 1), and
ChartDefinitionJson.Serialize writes it. Every RioCharts 1.x reads version 1 definitions: fields, chart type names,
their synonyms and option words may be added, but none is removed or changes meaning, so a definition you save today renders in
every later 1.x. A definition from a newer version is still read, with a warning, and fields this version does not know are left out.
Where the data comes from
Build datasets from your own rows, from CSV, or let an IChartDataSource load them when a definition asks
(e.g. FolderDataSource for a folder of CSV and JSON files). An optional description tells an agent what the data means.
ChartDefinitionJson.Schema() returns the JSON schema of a definition with a description of every option.
// One dictionary per row: field name -> value.
var rows = traffic.Select(t => new Dictionary<string, object?>
{
["timestamp"] = t.Hour,
["channel"] = t.Channel,
["orders"] = t.Orders,
});
var datasets = new Dictionary<string, ChartDataset>
{
["shop"] = ChartDataset.FromRows("shop", rows,
"Online store traffic per sales channel, hourly"),
["sales"] = ChartDataset.FromCsv("sales", File.ReadAllText("sales.csv"),
"Revenue per category and month, k€"),
};<RioChart Definition="definition" Datasets="datasets" />Try it
Edit the definition; it is read, checked and drawn in your browser. Start from an example, and use the datasets above.
The definition as read
{
"version": 1,
"title": "Orders per channel",
"y": {
"title": "Orders per hour"
},
"series": [
{
"x": "timestamp",
"y": "orders",
"groupBy": "channel",
"curve": "monotone"
}
],
"annotations": [
{
"value": 20,
"label": "Goal: 20 an hour"
}
],
"dataset": "shop"
}