Sub topic 13
Small charts in cells with SPARKLINE
This chapter covers the SPARKLINE function, which draws a small chart inside a single cell. It assumes you can select ranges, write simple formulas such as SUM, and read a basic chart's data layout. You do not need the chart editor here, because everything is controlled by the formula.
What a sparkline is and when to use one
A sparkline is a word-sized chart that sits inside a cell. It has no axes, legend, or title. Its job is to show the shape of a series (rising, falling, seasonal, spiky) next to the numbers it summarises.
Use a sparkline when you have many small series to compare at a glance, such as one row per product or region. Use a full chart when the reader needs to read exact values, compare against a scale, or see titles and a legend.
Because a sparkline is a formula, it behaves like any other cell content. It recalculates when the source data changes, it can be copied or filled down, and it can sit in the same table as the numbers.
Syntax
=SPARKLINE(data, [options])datais a range of numbers, such asB2:M2, or a single cell. A single row and a single column both work.optionsis an optional two-column array. Each row holds a setting name and its value. Names are text, so they go in quotes.
The options array uses curly braces. A comma separates the name from the value, and a semicolon starts a new row:
{"charttype", "column"; "color", "#1a73e8"}If you use a comma where a semicolon belongs, Sheets reads the array as one row and returns an error. In some locales the separators differ, so check your spreadsheet's locale if the array is rejected.
The default line sparkline
With no options, SPARKLINE draws a line. Suppose row 2 holds twelve monthly values in B2:M2.
=SPARKLINE(B2:M2)The line is scaled so that the lowest value sits near the bottom of the cell and the highest near the top. The scale is automatic and belongs to that one cell. Two sparklines side by side can look the same even when one series is in the thousands and the other is under ten. Keep this in mind when you compare rows, and see the section on ymin and ymax below.
Chart types
The charttype option selects the kind of sparkline. There are four.
| `charttype` | What it draws | Typical use |
|---|---|---|
| `line` | A connected line (the default) | Trends over time |
| `column` | One vertical bar per value | Comparing discrete periods |
| `bar` | A single horizontal bar split into segments | Progress or share of a total |
| `winloss` | Bars above or below a centre line by sign | Positive or negative outcomes |
A column sparkline with a custom colour looks like this:
=SPARKLINE(B2:M2, {"charttype", "column"; "color", "#1a73e8"})The winloss type does not scale bar height to the value. It draws every positive value as an up bar and every negative value as a down bar. It suits data such as profit or loss per month, where only the sign matters.
Line and column options
These options apply to line, column, and winloss.
| Option | Meaning |
|---|---|
| `color` | Colour of the line or bars. Accepts a name such as `"red"` or a hex code. |
| `linewidth` | Thickness of a line sparkline. |
| `xmin`, `xmax` | Limits on the horizontal axis. |
| `ymin`, `ymax` | Limits on the vertical axis. |
| `empty` | How to treat blank cells: `"zero"` plots them as zero. The default leaves a gap. |
| `nan` | How to treat text or error values: `"convert"` plots them as zero. The default leaves a gap. |
| `rtl` | When `TRUE`, draws the series from right to left. |
| `lowcolor`, `highcolor` | Colours for the lowest and highest column. |
| `firstcolor`, `lastcolor` | Colours for the first and last column. |
| `negcolor` | Colour for negative columns. |
| `axis` | When `TRUE`, draws a horizontal axis line. |
| `axiscolor` | Colour of that axis line. |
Option names are not case sensitive in practice, but write them in lower case, as above, to match the documentation. Options in the table that are specific to columns, such as lowcolor and highcolor, have no effect on a line sparkline.
Fixing the scale for fair comparison
Automatic scaling makes every row fill its cell. To compare rows honestly, give each one the same limits:
=SPARKLINE(B2:M2, {"ymin", 0; "ymax", 500})Now a row that peaks at 50 looks small and a row that peaks at 450 looks large. This is the same decision you make about axis scale in a full chart: a shared scale is truthful across rows, and an automatic scale emphasises each row's own shape.
Highlighting key points
For column sparklines, colour the extremes so the eye lands on them:
=SPARKLINE(B2:M2, {"charttype", "column"; "color", "#9aa0a6"; "highcolor", "#34a853"; "lowcolor", "#ea4335"; "axis", TRUE})The bars are grey, the tallest is green, and the shortest is red. The axis option helps when some values are negative, because the bars then grow up or down from a visible baseline.
The bar sparkline as a progress indicator
The bar type behaves differently. It reads one or more values and draws them as segments of a single horizontal bar. With a single value, it works as a progress bar:
=SPARKLINE(B2, {"charttype", "bar"; "max", 100; "color1", "#34a853"})If B2 holds 65, the bar is 65% filled. The max option sets the value that counts as a full bar. Without it, Sheets uses the sum of the data, so a single value would always fill the whole cell.
Bar-specific options include:
max: the value that corresponds to a full bar.min: the value at the start of the bar. It is rarely needed.color1andcolor2: colours for the first and second segments. Further segments usecolor3and so on.empty,nan, andrtl: these work as they do for the other types.
For a bar with two segments, pass two cells, for example B2:C2. The first is drawn in color1 and the second in color2.
Turning a percentage into a progress bar
When a cell holds a fraction such as 0.65, use a max of 1:
=SPARKLINE(B2, {"charttype", "bar"; "max", 1; "color1", "#1a73e8"})If the cell holds 65, use a max of 100. Match max to the unit of the data, not to how the cell is formatted.
Driving options from cells
Option values can be expressions, so a sparkline can respond to the data around it. This formula colours a progress bar green at 80 or above and orange below that:
=SPARKLINE(B2, {"charttype", "bar"; "max", 100; "color1", IF(B2>=80, "#34a853", "#fa7b17")})This is how you get conditional colouring in a sparkline. Conditional formatting rules do not recolour the chart itself, so the colour has to come from the formula.
Sparklines from computed data
The data argument can be any expression that returns a range or array. That means a sparkline can read from QUERY, FILTER, or an inline array.
A QUERY call can build a small summary table, for example total sales per value in column A for the North region:
=QUERY(A1:C100, "select A, sum(C) where B = 'North' group by A label sum(C) 'Sales'", 1)The result is a two-column table that updates when the source rows change. A sparkline cannot read a two-column result as one series, so point it at the second column only. Put the QUERY in a helper area, then reference its value column:
=SPARKLINE(F2:F20)You can also build the series inside the formula. This draws the last six values from column C:
=SPARKLINE(INDEX(C:C, COUNTA(C:C)-5):INDEX(C:C, COUNTA(C:C)))The INDEX(...):INDEX(...) form builds a range from two endpoints, so the sparkline always shows the most recent six entries. This assumes column C has no blanks and no header below the data.
One sparkline per row
To fill a table with sparklines, write the formula once and fill it down. Use relative references so each row reads its own data:
=SPARKLINE(B2:M2, {"charttype", "column"; "ymin", 0; "ymax", 500})Dragging the fill handle down changes B2:M2 to B3:M3, B4:M4, and so on. The options stay the same because they contain no cell references.
To make all rows with one formula, use ARRAYFORMULA carefully. SPARKLINE does not accept a multi-row range and return one chart per row, so fill down is the dependable method.
Sizing and layout
A sparkline fills its cell and scales with it. To make one readable:
- Widen the column so the line has room, often 150 to 250 pixels.
- Increase the row height if a column chart looks cramped.
- Keep numbers in an adjacent cell. A sparkline shows shape, not values, and it has no tooltip.
Sparklines have no title, legend, or data labels, and you cannot add them. If you need those, use a full chart from the earlier chapters.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `Formula parse error` | A comma used where a semicolon separates option rows, or a missing brace | Check that each option row is `"name", value` and rows are separated by `;` |
| Bar always fills the cell | `max` is missing or smaller than the data | Set `max` to the full-scale value |
| All sparklines look alike | Automatic scaling per cell | Set a shared `ymin` and `ymax` |
| Gaps in the line | Blank or text cells in the range | Use `empty` or `nan` to convert them, or clean the data |
| Nothing is drawn | The range is empty or all values are non-numeric | Check the range with `COUNT` |
| Colours ignored | Option name is misspelled, or it does not apply to the chart type | Compare against the option tables above |
Choosing between a sparkline and a chart
| Need | Use |
|---|---|
| Compare the trend of many rows quickly | Sparkline |
| Show a progress value beside a task | Bar sparkline |
| Read exact values or label axes | Full chart |
| Show several series with a legend | Full chart |
| Export or publish the visual | Full chart |
Exercise
Cell B2 holds a completion score of 72 out of a possible 150. Write a SPARKLINE formula that shows it as a blue progress bar, and say what the bar would look like if you left out the max option.
Show answer
=SPARKLINE(B2, {"charttype", "bar"; "max", 150; "color1", "blue"}) fills about 48% of the cell, because 72 is 48% of 150. Without max, Sheets takes the sum of the data as the full bar. With one value, that sum is 72, so the bar would be completely full and would not show progress.
Exercise
Row 5 holds twelve monthly profit figures in B5:M5, some of them negative. Write a formula that draws columns, colours negative months red and positive months green, and shows a baseline axis.
Show answer
=SPARKLINE(B5:M5, {"charttype", "column"; "color", "#34a853"; "negcolor", "#ea4335"; "axis", TRUE}). The color option sets the positive columns, negcolor sets the negative ones, and axis draws the zero line so bars visibly rise and fall from it.