Generate chart code
generate_chartGenerate ready-to-render chart code for a dataset: the backend picks a suitable chart type (or honors chart_type) and returns code that has passed its eligibility gates and quality checks. Pass the table as data ({columns, rows}) or csv_text. This hosted server receives your table, profiles it in memory and sends only the profile to generation; rows aren't stored or logged. The code and the render-ready data come back inline in the reply; this server writes no files. JavaScript (D3) unless you pass language or renderer. The D3 code is a portable render(container, data, options) function meant to be MERGED into your own app; an integration contract describes exactly how to call it. A generation uses your account's credits. The arguments chart_style, level_of_detail and culture are the person's choices, and the guide's 'settings' topic lists every choice a person can make with its options.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "generate_chart"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | No | A pre-typed {columns, rows} table — the shape a Fabric DAX query / dataframe already has. Alternative to csv_path/csv_text; when columns carry isMeasure/format/description the shape matches PBI fidelity with no guessing. | |
| wrap | No | Code form: 'none' (default) = the raw render() function to merge; 'esm' = same code plus `export { render };` so the file can be `import`ed. Both forms are accepted everywhere - @bicharts/chart-host strips the export clause before compiling - so this is a convenience, never a compatibility choice. | |
| model | No | Model code; empty = backend default. | |
| width | No | ||
| height | No | ||
| prompt | No | Freeform guidance for the generation — the same 'user commentary' lane the Power BI visual uses. Steer encoding/axes/emphasis in plain language, e.g. 'put Year on the x-axis, color by Division', 'render citations as a chord diagram', 'log scale on revenue', 'annotate the peak'. A RegiaBI plan reads up to 1000 characters of it (an account that brings its own model has no limit); text past that isn't read, and the result names it. | |
| culture | No | The caller's language and region as a BCP 47 tag such as 'de-DE', 'fr' or 'ja-JP'. Default 'en-US'. It is the language the chart's own text is written in (titles, axis labels, legends, notes), and it breaks the tie when a CSV's numbers or dates are ambiguous: 12.500 as twelve thousand five hundred or twelve and a half, 05.03.2024 as 5 March or 3 May. Set it from the end user's locale when you know it; it does not translate the data. | |
| formats | No | Per-column number/date FORMAT STRING (e.g. {"Revenue":"$#,##0","Margin":"0.0%"}). PBI supplies these from its model; a CSV can't, so provide them to steer number formatting. | |
| out_dir | No | Not accepted by this hosted server: this hosted server returns the chart inline; it can't write to your machine. | |
| overlay | No | The analytical layer the person asks for: 'moving_avg' = moving average, 'trend_line' = trend / regression line, 'anomaly' = anomaly highlights, 'confidence_band' = confidence band, 'forecast' = forecast / projection, 'yoy' = year-over-year comparison. It is strongly preferred where it applies to the chosen chart and data (the engine adds the derived measures it needs); where it can't apply, this data can't honor it. Unset: the engine decides. | |
| csv_path | No | Not accepted by this hosted server: this hosted server can't read files on your machine, so pass the table as data or csv_text. | |
| csv_text | No | Inline CSV text (alternative to csv_path). | |
| group_by | No | Columns that are the PRIMARY series/breakdown (the PBI 'Group by' well); the backend leads the visualization with these. | |
| industry | No | The industry the person names for the data, one of the listed values. A recognized metric name is used only when the columns are that industry's inputs for it. Unset: no industry context is added. | |
| language | No | Project source language: javascript/typescript generates D3 (the renderer @bicharts/chart-host draws), python lets the backend pick within Plotly/matplotlib. Omit for JavaScript (D3); `renderer`, when given, overrides it. | |
| limit_to | No | The subset the person asks for, passed on as an authoritative instruction to limit to or focus on exactly it: 'latest', 'top' (top / greatest), 'bottom' (bottom / smallest), 'most_common' or 'outliers'. limit_count says how many are kept. Unset: the engine decides. | |
| measures | No | Columns to treat as MEASURES (the PBI 'Values' well — fields the chart aggregates). Numeric non-identifier columns are measures by default. | |
| renderer | No | Force a specific renderer (overrides `language`). Omit to use `language`/auto-detection; 'VISUAL'/'' = let the backend choose. | |
| chart_type | No | Preferred chart type by name (honored unless the data shape disqualifies it). A form the person described (a map, bars) counts as named: pass the listed type of that form. | |
| date_grain | No | The time grain the person asks for on the time axis: day, week, month, quarter, year or decade. It is passed on as a strong request, and a different bucket the engine plans is rewritten to it when the dates give that grain 2 or more periods; data with no date column can't honor it. Unset: the engine chooses, from the number of periods the dates give at each grain. | |
| dimensions | No | Columns to treat as DIMENSIONS (a PBI category/axis well — fields to group/break by). Use for numeric codes/years that should NOT be aggregated. | |
| projection | No | The grain to draw chart_type at, for a type that fits only once the rows are totalled: the projection key a what-fits list gave for that type on this same data, copied exactly (e.g. "AggregateOut|CountryCode|"). It selects one way of totalling the rows; unset, such a type is drawn at the first grain that admits it. | |
| show_title | No | Whether the person wants a title inside the chart: true asks for a concise one, false asks for none. A yes or no, not the title's text. Unset: one narrower than 400 px or shorter than 300 px gets none; a larger one draws at random whether to have one, once per page. | |
| chart_style | No | Narrows the charts considered to one family: 'traditional' = the familiar forms (bar, stacked and grouped bar, line, area, pie, donut, card, gauge), 'non_traditional' = every other chart type. A chart named in chart_type is still honored unless the data shape disqualifies it, and 'traditional' also turns chart_variety off. Unset considers both families. | |
| compactness | No | How roomy the person wants the chart: 'spacious' = roomier margins and more aggressive aggregation of a high-cardinality column, 'balanced' = standard margins and label density, 'compact' = tighter margins and denser axes, aggregating only when cardinality clearly exceeds what fits. Unset: a level is drawn at random for each generation. | |
| data_labels | No | Whether the person wants the value printed on each mark: 'include' asks for the labels, 'exclude' for none. Per-mark labels are suppressed when more than 30 marks would carry one. Unset: the engine decides. | |
| font_family | No | The font family the person names for the chart's own text (titles, axis labels, tick labels, legends), or the one their house style says: a family such as 'Segoe UI' or a stack such as 'Segoe UI, Arial, sans-serif'. A font isn't a property of the data or the project. It applies to whichever renderer is chosen, and an unavailable family falls back to a web-safe stack rather than failing. Unset: the engine decides. | |
| limit_count | No | How many groups or categories the person asks to keep, from 1 to 10000. The engine keeps exactly that many by the measure, and its own Top-N, 'Other'-cap and cardinality rules yield to it. Unset: no limit from the person (the engine's own Top-N rules still apply). | |
| project_dir | No | Not accepted by this hosted server: this hosted server can't see your project folder, so pass language or renderer instead. | |
| rows_policy | No | 'auto' (default) = the engine decides how to summarize. 'all' = render EXACTLY one mark/row per source row, with no Top-N, no 'Other' rollup and no sampling. Use 'all' when your app depends on every row being present (a row-per-entity table, a point per location). | |
| style_block | No | The name of a style block saved on the account, as the person states it, or 'none' for no block. The chart follows that block's appearance notes and palette; a name the account doesn't have is reported back with the account's block names. Unset: the account's default block applies, if it has one. | |
| descriptions | No | Per-column human DESCRIPTION — gives the model semantic context the bare column name lacks. | |
| group_others | No | Whether the person allows the categories beyond a limit to be grouped into one 'Others' bucket. True is the same as unset: under a limit the rest is grouped and the total stays whole; with no limit the engine decides whether to group. False: the rest is dropped and nothing is grouped. Unset: grouping allowed. group_others true is not sent with rows_policy 'all', which draws every row. | |
| include_code | No | Include the full code in the response — governs BOTH the text block and structuredContent.code. Default: true, or FALSE when out_dir is given (the code is then already on disk, and a large chart's code can overflow a client's tool-output limit). Set it explicitly to override either default. | |
| non_additive | No | MEASURE columns that must NOT be summed (a ratio/average/rate — use mean, never stack). Usually auto-detected; this is an authoritative override. | |
| others_label | No | The name the person gives the 'Others' bucket, at most 40 characters; quotes, backticks and control characters are removed and longer text is cut. Unset: 'Other'. Not sent when group_others is false. | |
| palette_mode | No | Where the person wants the category colors from: 'host' = the app's options.palette, else the fallback palette; 'fallback' = one fixed palette in category-name order, the same in every chart; 'randomized' = a palette the engine proposes for this chart. The last two ignore options.palette. Unset: 'host'. | |
| preview_html | No | Not accepted by this hosted server: this hosted server returns the chart inline; it can't write to your machine. | |
| chart_variety | No | How much variety the person asks for: the probability, from 0 to 1, that the choice among the charts that fit this data is nudged toward a less conventional one, when the engine runs its planning pass. The nudge is among already-valid charts only: when only the obvious chart honestly fits, it is kept. It has no effect with an explicit chart_type, chart_style 'traditional' or reasoning_mode 1P or CP. Unset: the server's own default. | |
| privacy_level | No | How much detail to compute/share: 0 names only, 10 +counts, 20 +detailed stats (default), 30 +obfuscated sample rows. | |
| reasoning_mode | No | LLM pass structure; empty = backend heuristic. | |
| level_of_detail | No | The user's own preference for how much of the data to see, as they've stated it; it isn't a property of the data. 'High' = every observation drawn as its own mark (scatter, beeswarm, strip). 'Medium' = every row used, but shown as a distribution (box, violin, histogram). 'Low' = one mark per category (bars, cards, pies). Unset when the user hasn't stated one; unset is a proven no-op and the engine decides. This is a strong nudge, not a filter: it reorders charts that already fit, and an explicit chart_type still wins. | |
| derived_measures | No | Whether the person allows derived measures (ratios, z-scores, percent change, rank, index): 'discourage' keeps the chart to the raw columns (aggregations and sorts still apply); 'encourage' keeps them allowed and rules out the draw that would turn them off, without asking for more of them. Unset: a weighted draw for each generation. 'encourage' is not sent with forbid_derived_columns. | |
| in_chart_caption | No | Whether the person asks for a one-line subtitle under the chart title naming the chart type, any derived measure used and any non-default aggregation. Unset or false: none. | |
| legend_placement | No | Where the person wants the legend: 'outside' = in the chart margin, 'inside' = within the plot area where it overlaps the data least, 'none' = no standalone legend (the chart's own labels carry the names). A single-series chart draws no legend whichever is chosen. Unset: outside on a chart at least 500 px wide, the renderer's default on a narrower one. | |
| required_columns | No | Fields that MUST be visible in the output, each as its own column/channel. AUTHORITATIVE and VERIFIED: if the generated code never references one, the server regenerates automatically rather than returning a chart that silently dropped it. | |
| direction_of_good | No | Which way is good for each measure the chart judges, by its column name as sent: { "Bookings": "higher", "Cost": "lower" }. The person's own answer; unset when they haven't given one, and the engine then infers a direction where it can and leaves the rest neutral. | |
| forbid_derived_columns | No | True = show only fields present in the data (plus required_columns) — no per-capita, share-of-total, index, rank or z-score columns the engine would otherwise add. Use when your app owns the analytics and the chart is only the display. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geo | Yes | Region/basemap wiring; null for non-geo charts. | |
| code | No | The render() source. Omitted when include_code is false. | |
| data | No | The render payload {columns, rows, …} to hand render() — INCLUDING any __geoIso__/__geoLat__/__geoLon__ columns the caller cannot reconstruct. Present only when out_dir was NOT given; otherwise read files.data. | |
| build | Yes | MCP server build stamp — the bundle actually serving this call. | |
| files | No | Absolute paths written, when out_dir was given. | |
| binding | No | How `data` was built from your rows. Hand all three to @bicharts/chart-host - <BicChartGroup geo point destination> or createChartGroup(columns, rows, { geo, point, destination }) - and it builds the payload again from LIVE rows with the same columns; never rebuild __rowIdx__ or __geo* columns by hand. | |
| version | Yes | Server-side version number of this generation. | |
| geoPoint | Yes | Point-geocoding outcome (a route's ORIGIN end when geoPointDest is present). `placed` counts only rows with a coordinate: neither an unplaced nor an ambiguous name is plotted. Null when the chart geocodes no points. | |
| language | Yes | Renderer/language of the code (D3, PYTHON, …). | |
| settings | No | WHICH SETTINGS APPLIED to this chart and where each value came from, so a person can be told what was assumed. Present on every generation. | |
| chartName | Yes | The chart type the backend produced. | |
| dropLines | No | A 3D scatter's optional hover drop lines (a line from a hovered point to each back wall). requested: on, because the request asked; on/off: the user's answer, already applied to the generated component; ask: put askUser to the user ONCE before finishing, then pass hoverDropLines: true in the chart's options on a yes. Absent for every other chart. | |
| creditCost | Yes | Credits billed, when the server reported them. | |
| outputHash | No | The server's identity for this exact code: the same code always carries the same hash, which names the delivered code in a support request or a later report. Absent when the server sent none. | |
| codeSummary | No | The backend's own one-line description of what it built. | |
| optionsRead | No | The option names THIS chart's code reads (sorted). A chart honors nothing it does not read, so a live restyle - host.setOptions({...}), never a regeneration - can only move these. Some are the host's to supply (width, height, geo, geoPoint, uiState, setUiState, themeFg/themeBg); the integration contract says what each one does. Empty for a non-D3 language. | |
| userTextCut | No | Present when the prompt was longer than a RegiaBI plan reads (1000 characters; an account that brings its own model has no limit), so its tail never reached the model. Absent otherwise. | |
| capabilities | No | What the server declares the host may do with this chart, beside chartName. Absent when the chart has no capability: a chart type that declares none, a language other than D3, or an older server. | |
| geoPointDest | No | A route's DESTINATION end (an origin-destination flow map), geocoded apart from geoPoint, which is then the origin. `placed` counts only rows with a destination coordinate: neither an unplaced nor an ambiguous name is plotted. Present only for a route. | |
| hostContract | Yes | Host contract version the code targets; a host on a different MAJOR may not interoperate. | |
| chartMinWidth | No | The chart type's minimum width in pixels: below it the chart scrolls sideways rather than squash, and the component written with a D3 chart already does that. Never regenerate the type narrower to fit a phone. Absent when the type has none, or from an older server. | |
| correlationId | Yes | Ties this generation to the server-side log; it is what a support request quotes. | |
| chartMinHeight | No | The chart type's minimum height in pixels: below it the chart scrolls rather than squash. Absent when the type has none, or from an older server. | |
| warningMessage | No | Present when what was drawn differs from what was requested: a chart type that was overruled (it names the requested type, the reason and what was drawn instead), or an ask this data couldn't honor in full (it names the ask and why). Surface it to the user verbatim — never suppress it because the chart rendered fine. | |
| recoveredAfterMs | No | Present when the response stream was cut after the server accepted the request and this chart was then fetched back by its correlation: milliseconds from the start of the call to delivery. creditCost is null then: the fetch that delivered it reports only its own cost (a recovery is free), not the generation's, which was charged once, as usual. | |
| requiredD3Plugins | Yes | D3 plugin PACKAGES this code calls (e.g. ["d3-sankey"]) — install them and pass the host ONE d3 that carries them, built with assembleD3(d3, { ...plugins }) from @bicharts/chart-host (assigning onto an ES-module d3 namespace throws), or the chart throws mid-render. Empty for core-only d3 and for non-D3 languages. | |
| integrationContract | No | HOW TO RUN THIS CHART IN YOUR APP - the same integration contract the text block carries, here because a host that shows the model only this structured result would otherwise never see it: the payload and option shapes, the reference host (@bicharts/chart-host) with its React bindings AND its framework-free group (createChartGroup + createChartHost + attach) for a plain page or a UI framework reached through interop, this chart's d3 plugins and geometry, and the host-page prerequisites. Read it before wiring the chart in. | |
| improvementSuggestion | No | Present when the server has a note on how this chart was made: for example, that it is the standard version of the chart type because the tailored one didn't pass a quality check. It is meant for the person who asked for the chart. |