Sparklines—the word-sized line graphs—have become a standard dashboard element. In Stephen Few’s Information Dashboard Design, all but one of his recommended dashboards use sparklines to display time series data for key metrics or members of a dimension. Not only do sparklines provide a lot of information in a small space, they look great. What’s not to like?
Using just a portion of my iPhone’s screen, I can show the last quarter’s weekly sales data of a chain store’s furniture sales. It appears that the Eastern region might deserve a congratulatory call for ending the quarter strongly. Or did they?
A regular line graph shows the East’s sales have been remarkably stable, and overall sales were not affected by their “surge” in the last week.
This is the sparkline dilemma: too little context and it’s possible to see patterns or trends that aren’t; too much context and the sparklines are no longer compact and elegant. Statistical techniques can show the significance of changes in time series data, but two visual techniques might be easier and work just as well. First, you could add high and low values. Second, consider Few’s bandlines, which are now easier to implement with Tableau 8.1’s percentile function.
Elegant High and Low Labels
It’s tempting to use Tableau’s one-click label feature for min/max points, but these labels can get clobbered by the line in sparkline-sized graphs. Another option is to add a parallel worksheet with columns for the high and low values.
My favorite approach uses labels on invisible reference lines to position the high and low values vertically next to the line. If normal reference lines take a couple of minutes to produce in Tableau, these enhanced sparklines take maybe five minutes.
First add the high and low values by:
- Right-clicking the vertical axis > Add Reference Line and select Line per Pane for the maximum value. Choose Value for the Label and None for Formatting.
- Next, right-click the reference line in the graph, select Format, and change Alignment to right-justified, centered vertically.
- Repeat this for the minimum value.
Next, make room for the labels by extending the horizontal date axis with another invisible reference line placed a few weeks beyond the max date. Below I added five weeks:
Extended Axis = DATEPART(‘week’, WINDOW_MAX(MAX([Date]))) + 5
Right-click this new field, convert it to continuous, and drag it to the Detail button. Now you can add a reference line on the horizontal axis with this field and None for the label and line format.
I also like to highlight the high and low values on the line graph with circles. You can do this with another calculated field:
High-Low Points = IF WINDOW_MAX(SUM(Sales)) == SUM(Sales) OR
WINDOW_MIN(SUM(Sales)) == SUM(Sales)
THEN SUM(Sales) END
Drag this field to the right axis, right-click the axis, and select Synchronize Axis. On the Marks shelf, select All and remove Measure Names from Colors; then select the High-Low Points card and change the mark type to Circle and color to blue.
Bandlines attempt to solve the context problem by adding horizontal bands for each quartile: basically they’re a cross between a sparkline and a boxplot. (Few developed bandlines and describes them here.)
Tableau 8.1’s percentile function simplifies bandline implementation. Still, they require intermediate, if not Jedi-level, table calc skills, because the bands should be calculated across all of the dimensions—in this case Category, Region, and Date—to facilitate comparison. In our example, the top-performing Central region has many weeks in the upper quartile, while the South had a few bleak weeks.
The basic trick is to use two sets of table calcs to find the maximums at different levels of detail. The first determines the overall percentile, for example: 75th Percentile Table = WINDOW_PERCENTILE(SUM(Sales), 0.75) with Compute Using set to Table Across then Down (Date then Category and Region).
The second table calculation—WINDOW_MAX(SUM(Sales)) set to Compute Using Table Across—finds the max sales for each region pane and determines whether or not to place any particular reference band. In the Eastern region, for example, the max sales were $5,021, which is below the 75th percentile of $6,840. In this case we don’t want to place the 75th percentile reference band, because it will extend the vertical axis and flatten the sparkline.
Determining whether to place the line requires some additional logic, and the attached workbook has more detailed notes on the procedure I used. And if you’re new to table calcs, the bandline worksheet is a nice example of nested table calculations with different levels of aggregation.
Statisticians may cringe at the thought of using context instead of computation to determine significance, but it’s an important intermediate step and one that’s often easy to implement. Certainly a little subtle context can’t hurt. In any case, whenever you use sparklines, remember Edward Tufte’s guidance and ask yourself: Do the prominent visual effects convey relevant information?