Sub topic 13
Small charts in cells with SPARKLINE
Assume you know how to enter formulas, select ranges, and format cells in Google Sheets. A sparkline is a small chart drawn inside one cell. It is useful for showing a quick trend beside a row of data without creating a separate chart object.
Sparklines work best for compact summaries, such as monthly sales, weekly activity, or progress toward a target. They are less suitable when readers need exact values, axis labels, or detailed comparisons.
Create a basic sparkline
Suppose cells B2:M2 contain twelve monthly values. Enter this formula in N2:
=SPARKLINE(B2:M2)Google Sheets draws a line sparkline using the values from B2:M2. The chart updates when those values change. Copy the formula down to create one sparkline for each row.
The first argument is the data range. The optional second argument is an options array. An options array is a set of chart settings written as key-value pairs.
=SPARKLINE(B2:M2, {"charttype", "column"; "color", "#1a73e8"})This example changes the chart to columns and sets the column colour to blue. In this array, each setting has a name and a value. The semicolon separates rows in the array. Depending on your spreadsheet locale, Google Sheets may use different separators.
Choose a sparkline type
Google Sheets supports several useful sparkline types:
| Type | Best for | Example use |
|---|---|---|
| line | Showing movement over time | Monthly sales |
| column | Comparing values in sequence | Daily orders |
| bar | Showing progress toward a maximum | Completion percentage |
| winloss | Showing positive and negative outcomes | Wins and losses |
A bar sparkline can show progress toward a known maximum. If B2 contains a percentage from 0 to 100, use:
=SPARKLINE(B2, {"charttype", "bar"; "max", 100; "color1", "#34a853"})The max option tells Sheets that 100 represents a full bar. The color1 option sets the filled portion. Keep the source values and maximum on the same scale. For example, a value of 0.75 requires a max of 1, not 100.
Handle empty and invalid values
Blank cells are usually harmless, but text in a numeric range can produce an error or an unexpected result. Clean the source data before charting it. You can also use a conditional formula when a row might contain no values:
=IF(COUNTA(B2:M2)=0, "", SPARKLINE(B2:M2))This leaves the cell empty when B2:M2 contains no entries.
Use sparklines alongside labels and totals. A sparkline communicates shape quickly, but it does not identify individual values. Add a separate cell containing the latest value, total, or percentage when that number matters.
Exercise
Exercise
Write a formula that displays the values in C5:N5 as blue columns inside one cell.
Show answer
=SPARKLINE(C5:N5, {"charttype", "column"; "color", "#1a73e8"})