ShareYourGroupShareYourGroupGoogle Sheets

Only in Sheets

SPARKLINE function in Google Sheets

SPARKLINE draws a tiny chart inside a single cell from a range of numbers.

A sparkline is a chart small enough to live in one cell. Put one at the end of each row of a table and the reader sees at a glance which lines are rising and which are falling, without a single full-size chart. In Sheets it is a function, which means it can be copied down like any formula.

The examples on this page have no result to print, because the result is a picture inside the cell.

Syntax

=SPARKLINE(data, [options])
ArgumentWhat it is
dataThe range of numbers to draw.
optionsSettings in curly brackets, as pairs of name and value, such as {"charttype","column"}.

Examples

Sample sheet: Sales and targets laid out across the sheet, with the months along the top.
ABCDEFG
1MonthJanFebMarAprMayJun
2Sales470027005250230037504100
3Target400030005000300035004000

How it works

Give SPARKLINE a row or column of numbers and it draws a line through them, scaled to fit the cell. Make the cell wider or the row taller and the chart grows with it.

Chart types

charttypeDrawsGood for
"line" (the default)a linea trend over time
"column"small upright columnscomparing periods
"bar"one horizontal stacked barprogress towards a target, or parts of a whole
"winloss"blocks above and below a middle linewins and losses, profit and loss months

Writing options

Options go in curly brackets as pairs: a name in quotation marks, a comma, then the value. Separate the pairs with semicolons:

{"charttype","column"; "color","green"; "max",100}

The options can also be kept in two columns of cells, names in one and values in the next, and the range given as the second argument. That makes them easy to change without editing the formula.

Useful options

OptionApplies toDoes
"color"allthe main colour, as a name or a code such as "#0b8043"
"linewidth"linethickness of the line
"max", "min"barthe value that fills the cell; for other types use "ymax" and "ymin"
"highcolor", "lowcolor"column, winlosscolour of the highest and lowest columns
"negcolor"column, winlosscolour of negative values
"firstcolor", "lastcolor"column, winlosscolour of the first and last columns
"empty"line, columnhow to treat empty cells: "zero" or "ignore"
"rtl"allTRUE draws from right to left

A progress bar

A bar sparkline with one number and a max makes a neat progress bar:

=SPARKLINE(C2, {"charttype","bar"; "max",100; "color1","green"})

With a percentage complete in C2, the bar fills that share of the cell. Bars use color1, color2 and so on, one for each segment.

To change colour with the value, put an IF inside: "color1", IF(C2>=75,"green",IF(C2>=40,"orange","red")).

One per row

Write the formula in the first row and copy it down, as with any formula. Each row gets its own little chart of that row's numbers. Set "ymin" and "ymax" to the same values in every row if the rows should be comparable with one another. Without them, each chart is scaled to its own data, so a tiny wobble and a huge swing can look the same.

Limits

Common mistakes

In Excel

Excel has sparklines too, but as a feature, not a function: Insert, Sparklines places them in cells and a ribbon tab sets their options. A SPARKLINE formula does not survive conversion to an Excel file.

Related functions

The results on this page were worked out by us from the sample sheet; they were not produced by a script running Google Sheets. If Sheets shows you something different, please tell us.

This is an independent help site. It is not connected with or approved by Google. Google Sheets is a trademark of Google LLC, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.