Peltier Tech Blog

Excel Chart Add-Ins | Training | Charts and Tutorials | Peltier Tech Blog

 

Main menu:

Peltier Tech Chart Utilities for Excel Peltier Tech Panel Chart Utility Peltier Tech Waterfall Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

 
Excel Dashboards
 

 
Amazon Books
 

Subscribe

Site search

Subscribe

Site search


Recent Posts

Popular Posts

Privacy and License

Privacy Policy

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Poor Man’s Sparklines in Microsoft Excel

 
by Jon Peltier
Monday, January 30th, 2012
Peltier Technical Services, Inc., Copyright © 2012.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Microsoft introduced Sparklines as a native feature of Excel 2010. In a rare guest post, Sparklines For Excel vs. Excel 2010 Sparklines by Alex Kerin of Data Driven Consulting compared this new feature to existing third-party sparkline add-ins for Excel. In Sparklines and Data Bars in Excel 2010, I gave an introduction into how to use the new sparkline feature, demonstrated some of the options available for Excel 2010′s sparklines, and also showed how Excel 2010′s implementation of Data Bars was far superior to the original Data Bars in Excel 2007. I’ve also shown How to Make Horizontal Bullet Graphs that can be fitted into the cells of a dashboard.

While it’s good to see sparklines as a native Excel feature, the Excel 2010 implementation is rudimentary, and third-party sparkline products have more functionality and more features than the native Excel sparklines. Yet it’s not necessary to deal with add-ins in order to realize expanded sparkline capabilities in Excel. Excel’s regular charts can be used to create decent sparklines, and this article will show you how.

Native Excel 2010 Sparklines

It’s easy enough to insert sparklines into an Excel 2010 worksheet. First, make sure you are not in “Compatibility Mode”. Compatibility Mode means the active workbook is as compatible as possible with Excel 2003; the most obvious feature is that the worksheet grid has the Excel 2003 numbers of rows and columns, not the expanded grid introduced in Excel 2007.

Select the data range or the location for the sparklines, and click one of the Sparklines buttons on the Insert tab. In this example, I selected the range where I wanted the sparklines to appear, then clicked the Column Sparkline button. The dialog shows the selected range in the Location Range edit box.

Create Sparklines Dialog

Then I selected the data range, which appears in the Data Range edit box. For some reason, the Location Range edit box is cleared (and each box clears itself when the other box is edited), but Excel remembers the selected range.

Create Sparklines Dialog with Data Source Selected

Here are the sparklines with the location range still selected.

Built-In Sparklines in Excel 2010

Finally, here is the table with sparklines, with the active cell out of the way.

Built-In Sparklines in Excel 2010 (Clean)

Create Sparklines From Regular Charts

The protocol for generating your own sparklines using regular charts is presented below. This protocol works well in Excel 2010 and 2007. In earlier versions of Excel, charts have a border of several pixels around the plot area, so the chart area must be sized larger than the cell you want the sparkline displayed in. In earlier versions, there is also a limit to how much the chart can be shrunk and still show the entire plot area, so you’ll have to shrink the chart only partway, then shrink the plot area to a smaller fraction of the chart area size.

Keep in mind that while you can use regular charts for sparklines, the small size of a sparkline limits the amount of information you should try to cram into one. Leave out labels and limit yourself to about two series maximum in any given sparkline.

Start creating your sparkline by selecting the data for a single series.

Select Data for First Manual Sparkline

Insert a chart of the desired type. This is a typical Excel 2010 column chart.

Initial Appearance of Manual Sparkline

Now simplify formatting. Below left shows the chart with the chart area border removed and the chart and plot areas made transparent, so borders and cell fill colors show through. Below right, the legend and any axis and chart titles have been removed.

Remove Background and Borders, Remove Titles and Legend

The bars have been widened in the chart below left (by decreasing the gap width to 50%), and the major unit of the Y axis has been set to a small value, below right.

Fatten Up Bars (Reduce Gap Width), Shrink Major Y Unit

The axes have been hidden by selecting “None” for axis tick marks and axis tick labels and choosing “No line” for the axis line color. Note the size of the plot area within the chart.

Hide Axes and Note Plot Area Size

For best results, extend the plot area almost to the left and right edges of the chart, and stretch the bottom of the plot area to the bottom of the chart. Leave a large margin between the plot area and the top of the chart. In fact, you may have to increase this top margin in the sparkline, after the chart has been shrunk to fit a cell.

Resize Plot Area

Finally, shrink the chart and position it over the appropriate cell. If you hold down the Alt key while moving or resizing the chart, the chart edges will line up with the cell boundaries. If necessary, shrink the plot area from the top to increase the margin.

First Manual Sparkline Resized and Relocated

When all of the necessary formatting has been applied to the sparkline, and nothing else needs to be done, copy the sparkine and paste it into each of the other cells that need a sparkline. If you hold Ctrl and Alt while dragging the chart, a copy of the chart will be dragged into and aligned with the next cell.

Sparkline Copied and Pasted As Needed

All the charts are formatted identically. They also use the identical data, so let’s fix that.

Select the first sparkline. Notice how the source data is highlighted in the worksheet.

First Sparkline and Data Dange

Select the second sparkline. Notice how the highlighted data is from the first row. So is the highlighted data for the third sparkline.

Second Sparkline and First Data Range

You could change the source data by choosing Select Data from the Chart Tools > Design tab, or from the right-click menu. You could also edit the chart series formula. But the easiest way to adjust the chart data is to drag the range highlight with the mouse. Move the mouse over the highlight until its border thickens, then drag it to the new range. If you’ve selected the plot area or chart area, both the series name and the Y value highlights move together. If you’ve selected the series itself, the series name and Y data must be changed separately.

Data Range for Second Sparkline Being Moved

Correct the third sparkline’s source data in the same way.

Here is the finished table with sparklines. Looks like the built-in sparklines.

Corrected Data Ranges for All Sparklines

You can use any chart type: here’s a line chart with markers.

Works With All Chart Types: Here Is a Line Chart

Why Use Regular Charts?

There are a number of reasons to use regular charts rather than the built-in Excel 2010 sparklines.

Excel Version

One obvious reason is that you might not have upgraded to Excel 2010. If you’re using Excel 2007, the techniques shown here work the same way.

In Excel 2003 and earlier, the chart imposes a thicker border between the plot area and the chart area, so you have to oversize the chart to make the plot area fit as intended. Also, in earlier versions, the plot area only shrinks a certain amount within the chart area, so further shrinking of the chart truncates the plot area. The chart area can only be shrunk so far, but the plot area can be reduced further without shrinking the chart. The result is a chart that’s substantially larger than the cell it covers, but making the plot and chart areas transparent makes this no problem.

Mouseover Information

An important feature of a regular chart that is lacking in a sparkline, is the ability to mouse over a point and read relevant information from a popup. This is very useful in an interactive dashboard.

Native Sparklines Have No Mouseover Popups

Combination Charts

What if you want to compare a time series to other data, such as a target value.

Combination Chart: Target and Actual

Native sparklines can only plot one timeline, while a regular chart has more flexibility (as do some of the third-party sparkline programs).

Combination Sparkline: Target and Actual

Remember the limited resolution of a cell-sized chart: adding the simple target data to these sparklines is almost not worth the effort.

Other Embellishments

You may wish to reverse the vertical axis. For example, your costs are probably reported as positive numbers, but you want to show them as negatives.

Reverse Y Axis So Positive Values Plot As Negative

Native sparklines do not support reversing the vertical axis, but regular charts do.

Sparkline With Reversed Y Axis

Related Posts:

Learn how to create Excel dashboards.

Comments


Comment from teylyn
Time: Monday, January 30, 2012, 4:56 am

Nice post. That certainly comes in useful for pre-2010 versions. If you have 2010, though, combination charts are possible with 2010 Sparklines, too, albeit with a little bit of tricking. See http://www.teylyn.com/how-to-create-a-stacked-column-sparkline/

cheers, teylyn


Comment from Jon Peltier
Time: Monday, January 30, 2012, 10:16 am

Teylyn -

That’s a clever way to extract more out of Excel than Excel thinks it can do. I have a comment and a concern.

Comment: Whether your workaround or mine takes more effort is probably a matter of opinion, though I’d opine that using shrunken real charts provides more flexibility.

Concern: In earlier versions of Excel, having too many linked pictures leads to severe performance. “Too many” may be as few as one or two dozen. I haven’t tried this in Excel 2010, but there’s no reason to expect better behavior than in Excel 2007 or 2003. How extensively have you applied your trick in a single worksheet?


Comment from derek
Time: Monday, January 30, 2012, 12:39 pm

When I looked at the Excel 2010 sparkline bars you show, I was confused by the apparent smallness of the values around 80 or so. Then I realised the sparkbars are being shown with a non-zero origin! Yet another reason to use proper charts.


Comment from Jon Peltier
Time: Monday, January 30, 2012, 1:11 pm

Derek -

Good point, I hadn’t noticed. You can impose axis limits on sparklines. When I revisit this article (I should do so in a couple weeks) I’ll include that setting.

That also reminds me that I set my minimum to zero on the shrunken charts, but forgot to account for the maximum. I have a way to do that which keeps the axis limits the same on related charts with different data. That’s a worthwhile blog post, which I’ll then reference here.


Comment from Jeff Weir
Time: Tuesday, January 31, 2012, 8:04 pm

Hi Jon. I’ve previously used this a lot, as per my comments at http://peltiertech.com/WordPress/sparklines-for-excel-vs-excel-2010-sparklines-guest-post/

THe advantage over Excel’s native functionality for me was the ability to have multiple series. As per the example in the link above, three series can be put to good use in a sparkline.

I’ve just been working on a sparkline tool that connects dynamic excel graph sparkline to a pivottable in Excel 2010 that might be useful to readers. Plan on turning it into a commercial addin (along with some other pivottable trickery I’m working on), but meanwhile here’s my first cut.

It creates sparklines out of graphs that respond to changes in a pivot table structure. For example, it can handle:
* movement of fields between the Report Filter and Row fields
* addition of more source data including additional dates
* addition or removal of subtotals or grand totals.
* expansion or contraction of number of rows in the pivottable beyond the number of sparklines that currently exist. (i.e. extra are added or deleted as required)

No error handling yet…this is my first cut.

The code
* Counts how big the pivottable (pt) DataBodyRange is
* Works out how many sparklines are required given the DataBodyRange
* Adds named ranges corresponding to the last 12 months data for each row, and also the previous 12 months data for each row
* Amends where each sparkline series points to, in case the pivot structure has changed
* Sets the .MaximumScale of each sparkline axis to be 120% of the largest data point in the series. This way, each sparkline uses the full space available to display the trends, while allowing for a bit of space between its highest entry and the sparkline above.

I’ve uploaded a screenshot to https://skydrive.live.com/redir.aspx?cid=f380a394764ef31f&resid=F380A394764EF31F!283&parid=root and will also try to embed it below.

Pivot Sparklines Utility Screen Shot

Have uploaded sample workbook to https://skydrive.live.com/redir.aspx?cid=f380a394764ef31f&resid=F380A394764EF31F!284&parid=root

——————–

Hmmm…Skydrive seems to be playing up. Heres a link to the screenshot on google docs:
https://docs.google.com/open?id=0B1hgC5lSuLjVYTRmNTFhOWYtNDQwMC00MGI1LWFlZWQtMGExODRmYjBmMzIw

And here’s the workbook:

https://docs.google.com/open?id=0B1hgC5lSuLjVZmZiMjBmYWItZTlhOS00NWYzLWE3M2YtOWZhMDc2MjgwNjdl


Comment from Michael Pierce
Time: Monday, February 27, 2012, 6:21 pm

This is something that I’ve messed around with before, but your approach pointed out a few things I hadn’t considered before. So I have a few questions for you:

(1) Why do you set the major units on the vertical axis to “something small” (I used a value of 1)? It seems to cause the bars to use the vertical space more effectively, but I can’t come up with a reason why it would do that.

(2) Have you thought of deleting the horizontal axis rather than removing the tic marks, labels and line? Doing so seems to give the chart more vertical breathing room.

(3) Do you think it’s important to keep the vertical scale consistent across the multiple charts? For example, the Bravo data points cause the upper limit to reach 160, whereas the other 2 series only scale to 140.

(4) For a line chart, does it make sense to adjust the vertical axis minimum value to something other than zero? The charts end up being so squished vertically, most of the curve disappears. I know this is generally a bad thing to do with full size charts, but was wondering if the minimal size might allow for bending of that “rule.”

Write a comment

I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.

If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.

Read the PTS Blog Comment Policy.





Subscribe without commenting

Peltier Tech Chart Utilities for Excel Peltier Tech Waterfall Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Panel Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

Create Excel dashboards quickly with Plug-N-Play reports.