Chart syntax
insertChartFrom, updateChartFrom and the tools for an AI model take it with the format id chart-syntax.In the editor from A first chart:
editor.commands.insertChartFrom({ format: 'chart-syntax', content: 'bar\nJan | 42\nFeb | 48' })The type line
A first line that holds only a chart type, such as bar or Pie, with any spaces around it, is the type line.
- Without a type line, the chart takes the
typeoption of the command, such asinsertChartFrom, or else thechart.defaultTypeoption. - The type line wins over the
typeoption. - The type line stays in the text.
editChartAsTextwrites it back, andsetDiagramInputTyperewrites it.
A type registered with chartTypes is a type line in the Quick Input only. In code, such a line
is read as a data row, so pass the type as the type option instead.
How the rows are read
| Rule | How it reads |
|---|---|
| Delimiters | Comma, semicolon, pipe and tab, set with chart.delimiters |
| Header | The first row, when each cell after the first is text and not a number |
{H} | In front of any one cell, makes its row the header |
| Labels | The first column |
{L} | In front of a cell in the first data row, makes its column the label column |
| Empty cell | A missing value |
| Not a number | Text |
| Quotes | Text that may contain the delimiter. "" is one quote |
| Lists | A leading •, -, *, 1. or 1) is ignored, so a pasted list reads as rows |
| Single column | Lines without a delimiter are one series, labeled 1, 2, 3 |
| Empty line | Skipped |
So Month | Sales is a header and Jan | 2 a data row. A header with numbers needs {H}, such
as {H}Region | 2025 | 2026.
Which delimiter splits
The first line with an allowed delimiter decides it for the whole text. On a line with several,
tab wins over pipe, pipe over semicolon, and semicolon over comma. So Jan ; 1,5 splits at the
semicolon and reads 1,5 as a number.
Numbers
A number is digits with an optional sign, decimals and exponent, such as -2.5e3. 50% is text.
- With
chart.decimalSeparatorat its default'auto',1.5is read as 1.5, and so is1,5when the delimiter is not a comma. - Set
decimalSeparatorto'.'or','to fix the decimal separator. - Spaces inside a number are ignored, so
1 000is 1000. A dot or comma as a thousands separator is not: with'auto'and a pipe as the delimiter,1.000and1,000are 1.
Errors
An unclosed quote is an error on its line, such as Line 3: A quote is opened and never closed.
Reading a chart as text
editor.storage.diagrams.read({ format: 'chart-syntax' }) returns the selected chart's data as
Chart syntax text, without a type line, and pos picks another chart. It uses the delimiter the chart was typed with, or else the first of chart.delimiters,
and writes decimals with a comma unless that delimiter is a comma.
A pipe gets a space on each side, a tab none, and any other delimiter one after it.