# Charts

> Bar, line, area, pie and doughnut charts from a few lines of text, or from a grid you can paste a spreadsheet into

A **chart** shows numbers as a picture: bars to compare things, a line for a trend, a pie for the parts of a whole. In Kribble a chart is a few lines of text. You can write the text yourself, let an AI agent write it, or fill in a grid and let Kribble write it. Either way the note keeps the text, so the same chart shows in the editor, on published sites, in PDFs and in the IDE extensions.

```chart
bar
title: Signups by plan
series: Free, Team, Business

Jan: 820, 240, 60
Feb: 910, 265, 72
Mar: 1040, 301, 75
Apr: 1210, 344, 91
```

## Adding a chart

Type `/chart` in a note. A small example chart appears with its editing panel open:

- **The kind**: Bar, Line, Area, Pie or Doughnut, and for bars and areas **Stacked**, for bars **Horizontal**.
- **Title, X axis, Y axis and Unit.** The unit is written with every value: `$` and `€` go before the number (`$120`), `%` right after it, anything else after a space (`42 min`).
- **The data**, as a grid: a row per label (a quarter, a team, a country), a column per series (2024, 2025…). **+ Row** and **+ Series** add one; the × at the end of a row or next to a series name removes it. Enter moves down a row, and adds one at the end.
- **Colours.** The square next to a series name picks its colour: click it to step through them. Pies and single-series bar charts have one per row, to pick out a slice or a bar.
- **Text** shows the chart's text instead of the grid. Change either; the other follows.

**Paste from a spreadsheet.** Copy cells in Excel, Numbers or Google Sheets and paste them into the grid's first cell: the rows and columns fill in. If the copied cells start with a header row, its names become the series.

Click **Done**, or press Escape, when you're finished. To change a chart later, hover it and click **Edit**, or double-click it. Hovering a bar, a point or a slice shows its values.

In markdown, a chart is a fenced code block with the `chart` language, so the text above is all there is to it. Markdown viewers that don't know Kribble's charts, like GitHub, show the text, which still reads well.

## The text

### The first line: the kind

| Write | For |
| --- | --- |
| `bar` | comparing things side by side; one group of bars per row |
| `bar stacked` | totals made of parts: one bar per row, its segments the series |
| `bar horizontal` | rankings, and labels too long to fit under a bar |
| `line` | change over time |
| `area`, `area stacked` | change over time, where the amount (or how it adds up) matters |
| `pie`, `doughnut` | the parts of a whole: a slice per row |

`donut`, and plurals like `bars`, work too.

### Settings

Lines starting with one of these words and a colon set something about the chart. They can go anywhere after the first line, usually at the top.

| Setting |  |
| --- | --- |
| `title: Revenue by quarter` | The title above the chart. |
| `x: Quarter` | The title of the axis along the rows. |
| `y: Thousands` | The title of the value axis. |
| `unit: $` | Written with every value. |
| `min: 100`, `max: 200` | Where the value axis starts and ends. Bars and areas always start at zero. |
| `series: 2024, 2025` | Names for the columns of values, in order. Leave it out when there's only one. |

### Rows

Every other line is a row: a label, a colon and the values, separated by commas.

```
Q1: 120, 135
Q2: 140, 151
```

- Numbers are written plainly: `1200`, `-3.5`, `0.25`. A `$` (or `€`, `£`, `¥`, `₹`) before a number or a `%` after it is fine, and becomes the unit when there's none. `1,200` or `1.2k` aren't numbers.
- **Missing values** are left empty: `Q3: 120, , 140`, or `Thu:` for a row with none. A bar is left out, and a line has a gap.
- **Labels** can have spaces. A label with a comma, a colon or a bracket goes in double quotes: `"Sales, EMEA": 40`. So does a label that's one of the settings' words: `"title": 3`.
- **Colours** go in square brackets after a series name or a label: `series: Plan [gray], Actual [blue]`, or `Q4 [green]: 171` to pick out one bar or slice. The colours are blue, orange, teal, yellow, pink, green, purple, red and gray, or any `#rrggbb`. Without them, series get blue, orange, teal, yellow and so on, in an order chosen to stay apart for colour-blind readers.
- A `#` followed by a space starts a comment.

A pie draws the first value of each row. More than 8 slices are too many to tell apart: the 7 largest stay and the rest become one gray "Other" slice. A chart draws at most 8 series.

### When something's wrong

A line Kribble can't read doesn't break the chart: the rest still draws, and the editor lists what's wrong under the chart, with the line. A misspelt word gets a suggestion: `unknown colour "gren" (did you mean "green"?)`. `kribble check` reports the same in a markdown file, and agents get them as warnings when they write.

## More examples

A stacked bar chart:

```chart
bar stacked
title: Support tickets
series: Bugs, Questions, Feature requests

Mon: 12, 30, 5
Tue: 9, 28, 7
Wed: 15, 22, 4
Thu: 7, 25, 9
Fri: 4, 18, 3
```

A ranking with long labels:

```chart
bar horizontal
title: Time to first response
unit: min

Billing: 42
Onboarding questions: 18
Integrations: 65
"Security, compliance": 120
```

A doughnut, its total in the middle:

```chart
doughnut
title: Engineering time
unit: h

Building: 220
Meetings: 120
Review: 60
Support: 40
```

A line with a gap, and an axis that doesn't start at zero:

```chart
line
title: Server room temperature
unit: °C
min: 15

Mon: 21.5
Tue: 22.1
Wed: 21.8
Thu:
Fri: 23.4
Sat: 22.9
```

The full language, for anyone building on it, is in `spec/chart-language.md` in Kribble's repository.
