Why make 100 charts when one will do?
By Chris Gemignani
May 10, 2007
Find more about:
dashboard
excel
tools
tutorial
Charts are a great way to explore data. Here is some American baseball data showing player salaries over a five year period.

Charting this data with a line chart would allow us to see trends in salaries by team. However, when we use Excel’s default chart, we get something that looks like this:

That’s quite a mess. It would be a lot easier if we could create one chart for each row.
The OFFSET function is going to help. In its simplest form the OFFSET function works like this:
OFFSET(anchor, rows from anchor, columns from anchor)
That is, OFFSET will start with the anchor cell, go down a number of rows from that anchor and over a number of columns and return the value it finds.

We can use the OFFSET function to create cells that pull a single row of data out of the table dynamically. We create a new row atop of our data and create a series of OFFSET functions that all rely on a single cell (the big yellow one) for their row offset. So changing one cell will pull different rows of data into our fixed location.

Now, chart the data that doesn’t move.

After fixing the chart, we’d like to make it easy to change the value in the big yellow cell.

We can use Excel Forms to build a lightweight user interface. Bring up the Excel forms toolbar by rightclicking on any toolbar and choosing Forms. Place a scrollbar beside the chart.

Right clicking on the scrollbar allows you to Format Control. Link the control to the cell that is controlling all the row offsets. Now, moving the scrollbar will update the chart.

Now, the scrollbar controls the chart. Here is the baseball spreadsheet for you to play with: Baseball_offset.xls Have fun!

Note: this post is adapted from a presentation I gave at eMetrics 2007 in San Francisco.


25 comments | Show all comments only the last 5 are shown
derek said:
Very nice, but don't be too quick to discard the value of all the other lines. Why not present them as in the original mess, but in the thinnest strokes of identical lightest grey, against which your chosen line can stand out in bold blue?
Chris Gemignani said:
Thanks, Derek. Man, sometimes the posts just write themselves.
I've used the technique you describe and it can work very well indeed. In the past, I've done this this VBA, but probably a clever use of offset could make this work without the need for all the coding. We'll write this up sometime. Thanks!
derek said:
Clever use of offset? I added the whole lot in with Add Data, turned one line grey, used F4 and the up-arrow key to repeat thirty one times (you soon get into the rhythm :-) ) brought the blue offset line back up to the top of the stack ("Series 33") and finally, fixed the chart title link, that got destroyed by the Add Data stage. <a href="http://www.branta.demon.co.uk/infographics/Baseball_offset_2_derek.xls">See example</a>
Were you thinking that the grey line representing the selected data must be excluded? No need, it's hidden under the blue line.
Chris Gemignani said:
Beautiful. For the record, I was going to hide the grey line under the blue too. ;-)
Madan said:
Brilliant! I've been struggling with understanding the offset function for weeks, this made it finally make sense.
pg said:
Beautiful! And can I copy or export this little lovely Format Control box into PowerPoint, say?
derek said:
Sadly no. If you want to go to a live Excel application in the middle of a presentation, I suggest you design a hyperlink (Ctrl-K in Powerpoint) to a file that you already have open in Excel, and the Excel formatted to be as blank as possible (Full Screen display, Tools>Options>View set to remove all possible Excel features like gridlines and column headers etc.)
Josh said:
Yet again...SWEET tip. Thanks Chris.
ross said:
Yeah real nice,
The only thing i might do differently is place the scroll bar next to the data list, rather than the chat, might be a bit more intuative? line the way the lines is highlighted, good stuff.
Jeff said:
I might be missing something but I cant figure out who you get the chart title to change dynamically with the selection? I can trick it by labeling the series with the team name (and repositioning) but you have me stumped on the header function?
Darrell said:
Jeff, I know what you mean, its tough to now what team you're selecting. This is a minor usability issue, and not what Chris was attempting to demonstrate. The Offset function is mucho powerful for selecting different data sets in a big data table.
It would be better to have the user select from a list of the team names, rather than clicking sequentially through each one. This can be done with either a data validation, combined with a match() function, or a pick-list form. Incidentally I often use the cell underneath the pick-list form so it doesn't show when viewed / printed.
Another Tip:
I noticed that the Yankees 2005 number exceeded the manually set scale (223 vs. scale max of 200). This is a nuisance to detect/correct on one or two charts and a maintenance hassle if you have many charts.
One way that I found to have Excel automatically set a uniform scale among different data sets is to use the Min() & Max() functions over the entire data set and then Plot a fake data series (or two) with the min & max data.
In order to hide the fake data from displaying, you format the fake series by setting the Line & Marker to None (Format Data Series, Pattern: Line: None Marker: None). and then set the Value Axis Scale set to Auto. Excel accounts for the min / max data series when it calculates the Auto Scale setting and will always choose the same scale (from what I tested).
In this manner, the data will have a uniform scale among the different teams, and you don't have to worry about data exceeding the chart scale, or the Arizona Diamond backs looking equally profitable as the New York Yankees :)
Darrell said:
Jeff, a correction. I don't think I answered your question: you wanted to know how the chart title changed.
When you chart something in Excel, Excel guesses the chart title by picking the name of the first data series (the first argument of the first data series). In this case it is the
'Dynamic Charts'!$b$4 that instructs Excel what to call series One and the chart title.
The series in the spreadsheet defined as:
=SERIES('Dynamic Charts'!$B$4,'Dynamic Charts'!$C$3:$G$3,'Dynamic Charts'!$C$4:$G$4,1)
=Series(Arg1, Arg2, Arg3, Arg4)
where:
Arg1 is Series name, and default chart title if its Series #1
Arg2 is the names assigned to the category / X-axis
Arg3 is the data you want to chart, and
Arg4 is the number of the series
darrell said:
Jeff,
I was looking at Chris's file, not Derek's. I know the trick Derek used.
This tip works for any of the text boxes in a chart (that includes Chart Title, or even individual Data Labels). You can customize the text, either by overtyping it (Select box, hit F2 and type text), OR specifying a cell link.
To do this is a minor trick. You select the box, pause, Hit F2 and type the cell link into the formula box. I find it easiest to use the formula bar, rather than the text box. If you do it wrong, it creates an extra text box in the middle of the chart, if you do it right, the text is whatever is in the cell.
In this case, he selected the Chart Title, did the F2 - edit trick, and entered "='Dynamic Charts'!$B$4" .
Note that you cannot do a formula in the text box, you can only do a cell reference or a named range to a single cell. BUT the cell you reference can use any combination of formulas. Its especially useful to use concatenate() to incorporate figures or amounts into a title or data label.
Example:
in cell $b$4, you could enter
="New York Yankees - 5Yr total $"&sum(c4:g4)
and the chart will update have the title:
New York Yankees 5Yr Total $865.936
Better formatting:
="New York Yankees - 5Yr total $"&fixed(sum(c4:g4),0)&"MMs"
New York Yankees 5 Yr Total $866MM
That type of simple stuff wows my boss everytime :)
Tony Rose said:
Impressive! There has been a lot of great comments to help improve and build upon Chris' post. I do think there is some value to showing all of the basic line charts grouped together so you can visually see the differences in one glance, like Derek's example. Also, you may add a 5-year average column to sort from highest to lowest versus alpha. Keep up the great work!
Anyone else shake their head at the Yankees payroll?
derek said:
A recent discussion <a href="http://www.perceptualedge.com/blog/?p=116">referred to in Stephen Few's blog</a> led me to the pdf he wrote (because he couldn't put the graphics he needed to refer to in the comments box) about using Spotfire to create the (stupidly named, but actually quite clever) "parallel coordinates" graph type. This has inspired me to think of using Chris's baseball spreadsheet as the basis for a "Poor Man's Spotfire" using Excel.
I've made a start creating a view that "brushes" (fancy word for "selects") "The Highest/Lowest N baseball salaries in the year nnnn" and highlights those in thick blue against the thin grey of the rest of the teams. I used INDEX/MATCH instead of OFFSET. The next thing I want to do is try to highlight the "N teams whose pay profile looks most like Team T", using a least-squares fit.
When and if I make it a little more robust and add some more of the Spotfire functions Few uses in his article, I'll post it to Chris. Or y'all can start picking up the challenge on your own. How far can you push Excel to mimic exploratory data analysis with parallel coordinates and brushing? :-)
Chris Gemignani said:
Great idea, Derek. We were playing around the other day with another concept in Spotfire "heatmaps" for displaying tabular data. These turn out to be very easy to recreate in HTML tables. We'll post a solution sometime soon.
Fumiko said:
Thank you so much for sharing great ideas as always. It's clean and elegant, and overcomes the mess we could easily fall by using standard chart alternatives provided in original Excel.
I already have a data that I could use this solution. Once again,thank you for sharing this tip with us!!
craig said:
how can you switch the x and y axis when using Add Data?
thanks
Michael said:
How do you dynamically highlight the row item as the graph changes?
Chris Gemignani said:
Michael, I use a formula-based conditional format that looks roughly like: "ROW()=$A$2"
Sasikumar said:
It is really helpful to us to make a good presentation. It is very intresting also. let me know these type of other features in excel graphs
Mark said:
NICE IDEA!!! This would be REALLY useful for comparing multiple scenarios, which would mean I could select up to say 3 or 4 to plot at the same time. I will give that a shot, and thanks for the great start.
N Shivkumar said:
Excellent tip as to how to use control. Thanks a lot and keep posting new ideas.
derek said:
<a href="http://peltiertech.com/">Jon Peltier</a> has created a <a href="http://junkcharts.typepad.com/junk_charts/2008/01/football-rank-2.html">parallel coordinates tool in Excel</a> here, to explore quarteback preformance data. The two chart controls choose which player to highlight in red and which in blue. the rest of the players are pushed into the background as gray lines.
Randy said:
This is great. Is their a way to use the same scrollbar on multiple figures. Specifcally if I want to pictures side by side that flip as I scroll.
said:
Add a comment