Log InGet OrdStyle

How do I make a chart?

Write the numbers as an ordinary table, tag each header cell with what it should become — `[Bar]`, `[Line]`, `[X]` — and put a `CHART|` line directly underneath.

| Month | Sales [Bar] | Trend [Line] |
| Jan   | 120         | 118          |
| Feb   | 145         | 130          |

CHART|Monthly sales|0.6|1.0

The tag in each header cell chooses what that column becomes — [Bar], [Line], [Area], [Pie], [Donut], [Scatter], and [X] for the horizontal axis. The tags are not printed, so the table still reads as a table if you also want to show it.

After the title come the height-to-width ratio and the size.

Format > Insert Chart fills in the title, ratio, size, alignment and margins without your having to type them. Legend position, value labels and colors for every chart at once are columns on Settings > Table & Chart Styles; anything for one chart alone — an axis range, say — goes in braces at the end of the line:

CHART|Monthly sales|0.6|1.0|{legend=top ymin=0}

Why the numbers stay in the document

The chart has no data of its own: it is a view of the table above it. Correct a figure in the table and the chart redraws with it, which is the failure mode that spreadsheet-and-paste avoids only by luck.

It also means the numbers are still text in a text file — greppable, diffable, and reviewable in the same pull request as everything else.

Calculated cells

A cell can hold =FORMULA=RESULT. What sits between the first two = signs is calculated; what follows is the value shown:

| Product | Price | Qty | Total           |
| Apples  | 1.50  | 10  | =B2*C2=15       |
| Oranges | 2.25  | 8   | =B3*C3=18       |
| Total   |       |     | =SUM(D2..D3)=33 |

Cells are column letter plus row number (A1); ranges use two dots (D2..D5). SUM, AVERAGE, MIN, MAX, COUNT, ROUND, IF and about two dozen others are available.

A plot from live data instead

If the chart needs to come from somewhere else entirely, a Python block renders whatever the script writes out:

![Caption](script.py){width=40% align=center}
input data line 1
input data line 2
~~~

The lines between the opener and the ~~~ terminator go to the script on standard input, and the PNG or SVG it writes becomes the figure — regenerated every time you render.

See also