Everything you ever wanted to know about Sparklines in Google Sheets

Introduction

Sparklines are small, lightweight charts, typically without axes, which exist inside a single cell in your spreadsheets. They’re a wonderful, quick way to visualize your data, without needing the complexity of a full-blown chart.

They were first created by interface designer Peter Zelchenko around 1998. The term “sparkline” was coined by statistician and data visualization legend Edward Tufte.

Sparkline examples

I’ve been building a lot of dashboards in Google Sheets recently, making heavy use of sparklines to show data trends.

For example, here’s a column sparkline to show website users in the past 30 days:

Then, a combination of line sparklines and bar sparklines for social media metrics:

And finally, I’ve used a winloss sparkline chart to show web outages over the past 24 hour period:

So let’s explore how to create these charts and customize them to meet your needs. Links to all of the examples below are available for viewing in Google Sheets.

Line sparklines

This is the default choice for sparklines in Google Sheets, meaning that Google will default to showing a line if you don’t specify anything in your options.

Assume I have the following data in columns A and B of my Google Sheet. The idea here is to create a sparkline that displays the sales data from column B in a single cell, as a simple, lightweight chart without any additional details.

You’ll notice there are some blank values, some negative values and some text values in column B. That’s intentional and we’ll explore how to deal with each of those with the sparkline formula.

Default:

Since line charts are the default sparkline option, we don’t need to explicitly specify the chart type. So we can create a sparkline line chart with this simple formula:

=SPARKLINE($B$2:$B$21)

Color option:

Change the color of your sparkline by adding the color option/value pair, as follows:

If our data includes a column of x-values, then we can then specify a minimum or maximum for that axis. So from our data above, we now include column A in our spakrline formula argument, then specify a minimum and/or maximum in our sparkline options, for example:

=SPARKLINE($A$2:$B$21,{"xmin",5;"xmax",15})

This would only include values from column B, where the values in column A are between 5 and 15.

Note: I would advise a degree of caution with the xmin and xmax criteria. They are somewhat volatile and caused one of my Google Sheets to repeatedly crash.

Ymax and Ymin options:

Similarly we can specify bounds on the y values we plot in our sparkline, by using the ymax or ymin criteria. For example to only include values zero or above we would use:

=SPARKLINE($B$2:$B$21,{"ymin",0})

To set a ymax and ymin:

=SPARKLINE($B$2:$B$21,{"ymin",10;"ymax",20})

Empty option:

Use the “empty” option to determine whether blank cells in your dataset are rendered as 0 in your sparkline, or just ignored (the datapoint is not included in your sparkline). The formulas are respectively:

=SPARKLINE($B$2:$B$21,{"empty","zero"})

=SPARKLINE($B$2:$B$21,{"empty","ignore"})

Nan option:

Similar to the empty option above, use the “nan” option to determine how non-numeric cells (text cells) in your dataset are rendered in your sparkline. The options here are to convert to 0 or to ignore, as above, and the formulas are respectively:

=SPARKLINE($B$2:$B$21,{"nan","convert"})

=SPARKLINE($B$2:$B$21,{"nan","ignore"})

Rtl option:

Want your chart to show from right-to-left? Use the option “rtl”, which can be set to true or false, to specify the direction of your sparkline.

=SPARKLINE($B$2:$B$21,{"rtl",true})

Compare this sparkline to the first line chart and you’ll see the reversed direction:

Bar sparklines

You guessed it, these are small bar charts that exist inside a single cell. The usage is a little different than the line and column charts we've looked at so far though, because these are stacked bar charts. So you can point to a single cell of data and create charts based off of that, for example.

Using multiple bar sparklines to create charts:

This method works by setting a max value that applies to all your bar sparklines, using the "max" option. So step 1 is to determine a suitable maximum that works for your whole data range (consider using the MAX() formula to determine). In this example, 30 worked as my max option.

Winloss charts

These are a special type of column chart that plots only 2 possible outcomes: positive and negative (e.g. like a coin toss, heads or tails).

Here's the dataset for the following examples. The winloss sparkline is only concerned with whether a datapoint is positive or negative, it doesn't take relative sizes into account. So, in effect, it's really like a column chart of -1's and 1's.

Default winloss sparkline:

=SPARKLINE($B$2:$B$21,{"charttype","winloss"})

Color option:

=SPARKLINE($B$2:$B$21,{"charttype","winloss";"color","red"})

Lowcolor/Highcolor option:

Even though the winloss chart displays all the "columns" the same height, it is able to highlight the highest and lowest values in your original dataset. For example, the following formula colors the lowest values red (in the case of this dataset, that's the three -10 values):

Option/value pairs in cells

So far, we've encoded the options as an array of text strings inside of the sparkline formula, between the curly braces, e.g.: {"charttype","column";"axis",true;"axiscolor","red"}

However, we can instead list our option/value pairs in a range of cells in our spreadsheet, and then reference them in the sparkline formula.

Consider a dataset and option/value pairs setup as follows:

Then enter this formula into cell F2:

=sparkline($A$2:$A$21,{C2,D2;C3,D3})

to create your sparkline. We still need to enclose the options in the curly braces, { ... }, and separate the options and values with commas and semi-colons, but notice how we've used cell references instead of text strings this time.

The output of this formula is the following sparkline, in cell F2:

We can take this even further by putting all our options into two columns and then referencing those ranges:

The formula in this case is then:

=sparkline($A$2:$A$21,{C2:C9,D2:D9})

where my range of option/value pairs extend down to row 9 (adjust as needed to accommodate different number of options).

Lastly, we could get fancy by adding a data validation drop down menu to pick from the option/value pairs, e.g. for charttype, as shown in the following GIF:

69 thoughts on “Everything you ever wanted to know about Sparklines in Google Sheets”

I wonder if sparklines can be used to show the distribution of data. I find myself in many situations in which I’m looking at really basic statistics, but I may be missing out on the real data by looking at the distribution of data.

If I could easily see where there’s some significant normal or chi distribution, I would save time doing graphs one by one and straigh away see where there are interesting things to dig into!

You can definitely use sparklines to create mini histograms to look at whether data is normally distributed or not. For example, I would use a column chart to show this: =sparkline(A3:A23,{"charttype","column"}) as shown in this image:

However, you probably won’t be able to see the lowcolor on your sparkline, because it’s so close to the axis as to be invisible. If you try with a smaller date range, you should be able to see the effect, e.g. last week prices for Google ticker:

Hi Ben,
I experience the same problem as Renato.
I’ll get a message saying: “Function SPARKLINE parameter 2 has incorrect column size. Expected: 2. Actual: 1.”
I’ve tried to both change the column size and to merge two cells, but it doesn’t work. Hope you have a suggestion.
/Ken

Hi Ben,
Is it possible to highlight/color out of range values? Like for a specified max or min value (sort of like highcolor and lowcolor will do, but for as many high or low values outside of a certain range as are in the data)?
I’m thinking of charting lab results, where a “normal” range is expected and I’d like to highlight higher or lower than normal values. Could be in a line or column sparkline.
Ideas?
Thanks,
Saro

But I really like the stacked columns/bars idea, and might play with that too if I decide the colors would be easier to see that way. I just want an at a glance indicator if something was out of the expected range.

Great work Saro and thanks for sharing your worksheet! I hadn’t thought of using an array as the data for the sparkline, really interesting. I’ll have to update this post to deal with input arrays at some stage…

Is it possible to create a sparkline in googlesheets with multiple ranges? I’m trying to create a cell-based column chart that does not use consecutive data (though all in the same row). If so, is there also a way to filter out certain columns based on the column headers?

Yes, you can do that. After some experimentation I found using the filter function with an Array Formula will do the trick. The trick is to create an array of TRUE/FALSE corresponding to the columns you want to include/exclude. You can do this with a helper row (which has the advantage of being able to change the column selection easily) or by coding TRUE/FALSE directly in the formula.

For example, if I had data in columns B to J and I want to include only columns B,C,F,G,H,J then I can use either of these formulas:

Ben, thanks so much for your quick and thorough reply! (And for being a genius!)

The column headers in my spreadsheet are selected from drop-down lists, so I’m using your first suggestion (the helper row) and it’s working perfectly. All I needed was an =IF formula based on the column headers to generate the helper row.

I just started customizing Eric Bates’ highly recommended project management template (http://eric-bates.com/project-planning-template/) and wanted to find out more about sparklines. I was happy to find your very clear guide on how to use and adapt them — btw, your page is the second search result for “sparklines Google sheets” — First is Google support 🙂

Hi
Do you know how to create a sparkline in Google sheets that automatically updates based on last value in a column? For example if I have a column of data from A10 to AXX, where XX constantly changes, how do I create sparkline for this?

Sure thing! There’s a couple of ways to do this, one easy and one that involves some more advanced formulas but is rather crafty 😉 (there are probably/possibly other ways too).

1. Simply use the range A10:A in your sparkline formula, so it looks like this:

2. Use a formula to find the last cell in the column that is non-blank, create a string from that, create a named range for the cell with the string, use the indirect formula to refer to this string range inside your sparkline formula! Oooof, definitely harder!

Yes, you can get pretty close (minus the data labels) by using the Right-to-Left feature of bar sparklines. I use an IF formula to see if I have a positive or negative value, then choose the sparkline accordingly. Here’s the formula:

Do you know if it’s possible to put labels on the bars in a sparkline? I looked everywhere, and it doesn’t seem like a feature that exists, but I’m keeping my fingers crossed that you know how! Thanks.

Thanks a lot! Very usefull information – I deeply recommand! Only info, I couldn’ found was, how to make sparkline bar with gradient colors, but when I looked into Google Sheet documentation, it seems it is not an option, unfortunatelly.

Hi Ben,
Is it possible to change periods (e.g 6 months trend) in sparkline mini chart by drop down menu. I would like to see the actual period but changing the periods the sparklines are automatically changed.

You could create a drop-down menu for user input periods and then just modify the data range based of the user choice. The sparkline, based off this range, would then automatically update. Is that what you meant?

Hi Ben,
Let me specify my question. I have at least 2 countries and the figures with sparklines in one sheet, I have database on the other sheet, but the first sheet would like to change the periods and the figures and spirklines should be adjusted to the selected period showing the actual (selected period) figures and 6 months trends in sparklines for e.g 2 countries on the first sheet. with drop down menu and unique ID I have solved the figures to be updated based on the selected periods, but I am not able to link this to the sparkline. Hope it helps you.

Unfortunately there’s no way to do this with the line sparkline (although you can do it with the column sparkline). However, you could create two sparklines, one for the positive values and one for the negative values, and have them in two cells, like this:

The formulas to do this make use of the ymin and ymax attributes of the line sparkline:

Thanks for the helpful guide–I find myself referring back to it often. And your responsiveness in the comments! Two-part comment/question for you:

1. Seemed to me win/loss data could also (better?) be represented with bars take up all of the vertical space, and differ only in color: same info with more salience / less wasted space. If it’s helpful to you/others, this is possible by coding wins as a positive high value, and losses as a positive low value–here, 2 & 1 respectively:=SPARKLINE({2,2,1,2,2},{"charttype","column";"lowcolor","red";"ymax",1})

2. In the process of figuring that out, I came across what seems to be a bug: ymax/highcolor and ymin/lowcolor don’t seem to play well together. A simple way to see this is with this sparkline, which highlights the 2-bar rather than the 3-bar.=SPARKLINE({1,2,3},{"charttype","column";"highcolor","red";"ymax",2})
Is that something you’ve experienced as well? Know any workarounds, or have a direct line to Google?

I like it, it stands out more although you lose the impact of losses being negative. I think the winloss with the axis is a good representation, especially if you can widen the row.

For point 2, I wish I had a direct line into Google! 😜 It does indeed look like the sparkeline formula selects the highcolor after applying the y-axis value of 2, but then recognizes the last value as different, but not larger. Interesting. You could try reporting the issue through the sheet help menu: Help > Report a problem…

Nice–great to see all the options visualized so clearly and concisely.

I’m kicking myself for commenting slightly too soon, though–I’ve realized since my post that because of the problem in (2), the method in (1) is unreliable–it breaks down if if there are any zeros/blanks:

The auto-scaling also messing things up if there are all wins or all losses.

A seemingly-reliable workaround uses different values: “win” = some value (1.00), “loss” = a visually indistinguishable amount more (1.01). The exact “loss” amount gets a highcolor. Adding in ymin solves the autoscaling issue. So for the same win-blank-loss-win-win sequence, it’s:

Is there a formula for a bar graph to show the differences between dates? I’m trying to develop a chart showing dates of different projects but I can’t figure out the sparkline formula to show date calculations.

You can subtract dates to get the days between them, and then use this value in your bar sparkline. Subtracting dates is the same as subtracting ordinary numbers (because dates are in fact stored as numbers in the background).

If you want to actually use dates in your chart in some way, then you’ll want to use a regular chart since sparklines are very lightweight and deliberately limited.

One thing: I would like to integrate my COLUMN-sparklines into a Google-presentation-file (where I can update the chart with one click – like in other cases) – but I can not find a way to do this. It seems, that it works only by integrating the “classic” line-sparkline-chart/diagram. Do you have any ideas how I could get this done?

Is there a way to create a column header array formula for sparklines? I have data being submitted from google forms and would like to use a single formula to create sparklines automatically down a column instead of having to have a formula in each cell

When I use column sparklines and want to ensure my entire worksheet has a comparison of value across all the data (so for e.g. an $18k in the row above should show taller in the column chart than a $9k in the row below it), how do I adjust the axis setting within a Google Sheets doc? Please see video example of what I’m trying to achieve in normal excel (not within Google Sheets) – https://www.screencast.com/t/HShztzJCNY

1. comparison between LTP, vs S1, S2 and R1, R2; where LTP is a middle point and .S2, S1 as lower band and R1, R2 as the higher band. and the chart colour moves according to LTP price. All the condition in one cell. (Example- if LTP Price increase to words R1, R2 then Green should grow and vice versa.)

2. comparison between PIVOT and LTP where LTP price is on another sheet and PIVOT also.(Example- sheet1 having LTP Price and sheet2 have pivot price)