# Sparklines

> Line, column and win/loss sparklines drawn inside cells, with high, low, first, last and negative point colours, kept in xlsx files.

A sparkline is a tiny chart inside one cell. It shows the trend of a row or column of values next to the numbers themselves.

```ts
sheet.addSparklines({
  type: 'line',
  color: '#1f6feb',
  highPoint: true,
  lowPoint: true,
  sparklines: [
    { cell: 'N2', range: 'B2:M2' },
    { cell: 'N3', range: 'B3:M3' },
    { cell: 'N4', range: 'B4:M4' },
  ],
});
```

**`SparklineGroup`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface SparklineGroup
```

| Property | Type | Description |
| --- | --- | --- |
| `type` | `SparklineType` |  |
| `sparklines` | `{ cell: string; range: string }[]` |  |
| `color?` | `string` |  |
| `negativeColor?` | `string` |  |
| `markers?` | `boolean` |  |
| `highPoint?` | `boolean` |  |
| `lowPoint?` | `boolean` |  |
| `firstPoint?` | `boolean` |  |
| `lastPoint?` | `boolean` |  |
| `negativePoints?` | `boolean` |  |
| `markerColor?` | `string` |  |
| `highColor?` | `string` |  |
| `lowColor?` | `string` |  |
| `firstColor?` | `string` |  |
| `lastColor?` | `string` |  |
| `lineWeight?` | `number` |  |
| `minAxis?` | `number` |  |
| `maxAxis?` | `number` |  |
| `showAxis?` | `boolean` |  |

Sparklines come in groups that share their settings, as in Excel. Each item draws the values of `range` into `cell`. A range may name another sheet: `'Monthly sales'!B2:M2`.

| `type` | Shows |
| --- | --- |
| `line` | A line through the values. Empty cells leave a gap. `markers: true` draws every point. |
| `column` | One bar per value, from zero. |
| `winLoss` | An up bar for positive values and a down bar for negative values, all the same height. Zeros are left out. |

Point highlights: `highPoint`, `lowPoint`, `firstPoint`, `lastPoint` and `negativePoints` colour those points with `highColor`, `lowColor`, `firstColor`, `lastColor` and `negativeColor`. `minAxis` and `maxAxis` fix the vertical scale, which otherwise follows each sparkline's own values. `showAxis` draws the zero line when a sparkline has both positive and negative values. `lineWeight` sets the line width in pixels.

Sparklines redraw when their values change, scale with the cell, and are drawn under the cell's own text. Cells with a sparkline are announced as "sparkline" to screen readers.

| Method | Purpose |
| --- | --- |
| `addSparklines(group, sheet?)` | Adds a group. A cell that already has a sparkline gets the new one. |
| `clearSparklines(range?, sheet?)` | Removes the sparklines in a range, or all of them. |
| `getSparklines(sheet?)` | Returns copies of a sheet's groups. |

Sparklines follow inserted and deleted rows and columns. They are saved to xlsx in Excel's sparkline format; see [Excel files](https://docs.birchui.com/spreadsheet/xlsx.md#what-round-trips).
