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

Chart with 1 series. Revenue: 12 values, lowest 68 at Mar, highest 149 at Dec. 6080100120140160JanFebMarAprMayJunJulAugSepOctNovDecUse Left and Right to move between points. Press Escape to leave.
Code
JSON
{
  "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:

Data

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 timechannel textsessions numberorders numberrevenue numberresponseMs number
2026-11-14 00:00Web778181283175
2026-11-18 04:00Web2987577165
2026-11-15 09:00App892166131
2026-11-19 14:00App3679742154
2026-11-16 19:00Marketplace3528651169

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.

Shares from inline rows

Inline rows and auto: four shares that add up to 100 become a donut.

Donut chart with 4 items: Search 48, Social 27, Email 15, Direct 10. SearchSocialEmailDirect48%27%15%10%100TotalUse the arrow keys to move between slices. Press Escape to leave.
Code
JSON
{
  "data": [ { "source": "Search", "share": 48 }, { "source": "Social", "share": 27 },
            { "source": "Email", "share": 15 }, { "source": "Direct", "share": 10 } ],
  "series": [{ "type": "auto", "x": "source", "y": "share" }]
}
TypeWhat it reads
line, area, barx (time, number or category) and y. A stack name stacks series; "horizontal": true on the chart lays bars sideways.
pie, funnel, radialBarx names the slice or stage, y its size. innerRadius makes a donut.
scatterTwo numbers, x and y; a size field makes bubbles.
heatmap, calendarA heatmap: x columns, groupBy rows, y the color. A calendar: a time x, one square per day.
histogram, boxPlotHow values spread: a histogram counts a number field in bins; a box plot shows each group's quartiles.
rangeBar, dumbbell, rangeAreaFrom–to values: a timeline's row, start and end; a dumbbell's from and y; a band's low and y.
waterfall, candlestickSteps that add up (with total rows), and prices with open, high, low and y as the close.
gauge, bulletOne value against a scale (min, max, target), or a value per row against its targetField.
treemap, radar, map, mapBubbleNested 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:

  • filter keeps the rows that match all conditions: [{ "field": "channel", "op": "eq", "value": "App" }], with eq, ne, gt, gte, lt, lte and contains.
  • timeBucket groups a time x per minute, hour, day, week, month, quarter or year (or auto), and aggregate combines the rows in each group or category: sum, average, min, max, count or last.
  • groupBy makes one series per value of a field: one line per sales channel.
  • sort ranks the categories by value, and limit keeps the first N: a top 10.

Revenue per day and channel

Hourly rows grouped per day, summed, one series per channel, stacked.

Chart with 3 series. Web: 7 values, lowest 24,872 € at 11/20/2026 12:00 AM, highest 27,422 € at 11/16/2026 12:00 AM, trend stable. App: 7 values, lowest 16,353 € at 11/14/2026 12:00 AM, highest 17,751 € at 11/20/2026 12:00 AM, trend rising. Marketplace: 7 values, lowest 8,602 € at 11/18/2026 12:00 AM, highest 9,586 € at 11/20/2026 12:00 AM, trend stable. 020k40k60kNov 14Nov 15Nov 16Nov 17Nov 18Nov 19Nov 20€WebAppMarketplaceUse Left and Right to move between points, Up and Down to change series. Press Escape to leave.
Code
JSON
{
  "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.

Chart with 1 series. Revenue: 3 values, lowest 224 k€ at Camping, highest 447 k€ at Shoes. 0100200300400500ShoesClothingCampingUse Left and Right to move between points. Press Escape to leave.
Code
JSON
{
  "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

Chart with 2 series. Revenue: 7 values, lowest 51,729 at 11/14/2026 12:00 AM, highest 53,900 at 11/16/2026 12:00 AM, trend stable. Sessions: 7 values, lowest 26,560 at 11/14/2026 12:00 AM, highest 27,198 at 11/17/2026 12:00 AM, trend rising. 010k20k30k020k40k60kNov 14Nov 15Nov 16Nov 17Nov 18Nov 19Nov 20Sessions€RevenueSessionsGoal: 7,000 sessions: 7,000Goal: 7,000 sessionsUse Left and Right to move between points, Up and Down to change series. Press Escape to leave.
Code
JSON
{
  "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

Chart with 0 series. No data available. No data available
Code
JSON
{
  "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.

C#
// 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€"),
};
Razor
<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.

Chart "Orders per channel" with 3 series. Web: 168 values, lowest 2 at 11/14/2026 8:00 AM, highest 28 at 11/19/2026 8:00 PM, trend stable. App: 168 values, lowest 1 at 11/15/2026 7:00 AM, highest 18 at 11/16/2026 9:00 PM, trend stable. Marketplace: 168 values, lowest 1 at 11/14/2026 8:00 AM, highest 10 at 11/16/2026 8:00 PM, trend stable. Orders per channel0102030Nov 15Nov 17Nov 19Orders per hourWebAppMarketplaceGoal: 20 an hour: 20Goal: 20 an hourUse Left and Right to move between points, Up and Down to change series. Plus and minus zoom, Shift with Left and Right pans, 0 shows all data. Press Escape to leave.
  • series[0].type: 'spline' read as line.
The definition as read
JSON
{
  "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"
}
An unhandled error has occurred. Reload 🗙