Chart syntax

The chart syntax is how a chart is written as text: one row per line, cells split by a comma, semicolon, pipe or tab, and an optional first line that names the type. It is what you type into the Quick Input, and its format id is chart-syntax.
Pro ExtensionAlphaPilot program
bar
Month | Online | Retail
Jan   | 42     | 30
Feb   | 48     | 28

The type line

  • A first line that holds only a chart type, bar, pie or a type registered with chartTypes, names the type, as the header of Mermaid source does. Case and the space around it do not matter.
  • Without it, the chart takes the type it was given, or chart.defaultType.
  • It wins over a type given separately, so the text alone says what the chart becomes.
  • It stays in the text. editChartAsText writes it back as the first line, and setDiagramInputType rewrites it.

How the rows are read

RuleHow it reads
DelimitersComma, semicolon, pipe and tab, set with the chart.delimiters option
HeaderThe first row is the header when it holds no number outside the first column
{H}In front of a cell, marks it as a header cell explicitly
LabelsThe first column holds the labels
{L}In front of a cell, marks it as a label explicitly
Empty cellA missing value
Not a numberA cell that is not a number is kept as text
QuotesA cell in double quotes may contain the delimiter
ListsA leading bullet or number (•, -, *, 1.) is ignored, so a pasted list reads as rows
Single columnLines without any delimiter are one series of values, labeled 1, 2, 3 and so on

Which delimiter splits

  • The first line that contains an allowed delimiter decides it for the whole block.
  • On a line with several, a tab, a pipe or a semicolon wins over a comma.
  • So Jan ; 1,5 splits at the semicolon and reads 1,5 as a number.

Numbers

  • With decimalSeparator: 'auto', 1.5 is read as 1.5.
  • With 'auto', 1,5 is read as 1.5 too, when the delimiter is not a comma.
  • Set decimalSeparator to '.' or ',' to fix the decimal separator.
  • Thousands separators are not read.

Errors

  • A quote that is opened and never closed is an error on that line.
  • An error names the line, for example Line 3: A quote is opened and never closed.

In code

The same text works without the box, through insertChartFrom, updateChartFrom and the tools for a model:

editor.commands.insertChartFrom({ format: 'chart-syntax', content: 'bar\nJan | 42\nFeb | 48' })

editor.storage.diagrams.read({ format: 'chart-syntax' }) writes a chart's data in the chart syntax, with the delimiter it was typed with.

DelimiterWritten as
Pipe|
TabA bare tab
Any otherThe delimiter, then a space