Record charts
Declarative specs, aggregated data and the dashboard grid.
Raw Markdown for agents: records_charts.md. MCP: read_docs("records_charts").
A chart is a small declarative spec over one record type. The database groups and aggregates, the web app draws the result, so a chart never ships single records. Saved charts live in the Records area and can be placed on the space dashboard.
Workflow: records.types.list for the record_type_id, records.types.describe for the field keys, records.charts.data with an inline spec to check the numbers, then records.charts.create. records.charts.update replaces the whole spec and needs expected_revision.
Spec: {"title": "Revenue per month", "source": {"record_type_id": "<uuid>"}, "x": {"field": "issued", "bucket": "month"}, "measures": [{"op": "sum", "field": "total", "label": "Revenue"}], "chart": {"type": "bar"}}. source also takes view (key of a saved view as base filter), filter (the same filter tree as records.rows.query), date_field plus either last_days for a rolling window (today included) or period for a calendar window.
Periods: {"preset": "this_month"} with this_month, last_month, this_quarter, last_quarter, this_year or last_year covers the whole calendar period in local days of time_zone (this_month includes the rest of the month); {"preset": "last_n_days", "days": 30} ends today; {"preset": "custom", "from": "2026-01-01", "to": "2026-03-31"} takes inclusive ISO days, at most 3650.
records.charts.data also takes days or period (overrides the spec's window, not both), filter (an extra filter tree joined with AND to the view and source filters) and q (the search of records.rows.query over title and text fields).
Dimensions: x and the optional series are {field, bucket, top}. field is a text, number, boolean, date, datetime, single_select or multi_select key, created_at or updated_at, a record relation key (groups by the title of the linked record) or relation_key.field_key for one hop to a field of the linked type. bucket is day, week, month, quarter, year or auto and only fits dates. top keeps the N groups with the largest absolute value of the first measure and folds the rest into "other", which always sorts last. Text, select and relation dimensions without top default to 7 for series, 12 for x and 6 for the x of a donut; set top up to 50 to override. A multi_select or many-to-many dimension counts a record once per value or link.
Measures: 1 to 4 of {op, field, label}; op is count (no field), count_distinct, sum, avg, min or max; sum, avg, min and max need a number, money or count field. A saved chart uses either series or several measures, not both. An inline spec sent to records.charts.data by an agent may combine both and apply min and max to date or datetime fields; such a spec cannot be saved. Money sums ignore the currency; the result carries the warning mixed_currency when more than one currency was added up, and a kpi returns null for that measure instead of a sum across currencies. A kpi chart in a view's config.kpi_chart_ids leaves the view when it is deleted, stops being a kpi or moves to another record type.
Formulas: op formula takes expr instead of field and computes with + - * / and parentheses over aggregates: sum, avg, min and max of a number, money or count field or of a per-row expression, count() and count_distinct(field). Every field sits inside an aggregate, aggregates do not nest, and a division by zero yields null. Examples: margin {"op": "formula", "expr": "sum(revenue)
- sum(cost)", "label": "Margin"}, average ticket "sum(revenue) / count()", line value "sum(price * quantity)". format.unit percent expects 0-100, so a share is "sum(profit) / sum(revenue) * 100". With format.unit currency the result carries the currency of the first money field in expr.
Chart types: kpi (no x; add "compare": "previous_period" with source.date_field and last_days or period for the change against the window before), line, area, bar (stacked, horizontal), donut (x and one measure) and heatmap (x, series, one measure). "today": true on a line, area or bar chart with a date x draws a line at the current bucket; a bar chart with one series also colors earlier buckets red and the current and later ones green, which suits due dates. KPIs relative to today use the relative filter operators, e.g. overdue = {"field": "due_date", "op": "older_than_days", "value": 1}. Example by relation with a top list: {"title": "Open invoices by supplier", "source": {"record_type_id": "<uuid>", "filter": {"conditions": [{"field": "status", "op": "eq", "value": "open"}]}}, "x": {"field": "supplier", "top": 10}, "measures": [{"op": "sum", "field": "total"}], "chart": {"type": "bar", "horizontal": true}, "sort": "value_desc"}. KPI example: {"title": "New orders", "source": {"record_type_id": "<uuid>", "date_field": "created_at", "last_days": 30}, "measures": [{"op": "count"}], "chart": {"type": "kpi"}, "compare": "previous_period", "better": "up"}.
Display: agents never see the chart, so pick the shape that reads right. A KPI shows one measure; the title is its label and the description one short sentence. With compare set better to "up" or "down" so the change is colored, otherwise it stays neutral. Money fields carry their currency. Questions over time use a date x; empty periods show as 0. Combine two measures only when they share a similar unit: very different scales get a second axis, so prefer two charts.
Result: columns [{key, role x|series|measure, label, type, options, currency}] and rows as arrays in column order; numbers arrive as strings without trailing zeros, dates as ISO days. truncated is true when the row limit cut the result. window is {from, to} in inclusive ISO days, null when the chart has no date field. A kpi with compare also returns previous (the measures of previous_window, null when they are in another currency), previous_count (rows in previous_window; 0 means no change can be computed) and previous_window. A running calendar period compares the days elapsed so far with as many days from the start of the previous period, capped at its end (30 March against all of February); a closed period compares with the whole previous one; last_days, last_n_days and custom with as many days right before. Agents get 200 rows by default, at most 2000 with limit.
Dashboard: records.charts.board_get returns sections, records.charts.board_update replaces them: {"sections": [{"id": "sales", "title": "Sales", "items": [{"record_chart_id": "<uuid>"}]}]}. The web app arranges the tiles automatically: KPIs form a strip on top, the other charts share rows of equal height. span and height are accepted but ignored.
Errors: invalid_chart_spec explains what does not fit the schema, unknown_field means call records.types.describe, chart_source_missing means the record type or a field of a saved chart is gone, chart_query_timeout means narrow the filter or window or mark the grouped fields as indexed.