PTS Blog

Main menu:

PTS Utilities

Commercial Utilities developed by Peltier Technical Services

Waterfall Chart
Box and Whiskers


 

Excel Books

Books that I own and use while developing in Excel

Subscribe

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Buy me a coffee

If this topic or the blog itself has been helpful, why not support further development by treating me to coffee?


Privacy Policy

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

Display One Chart Dynamically and Interactively

by Jon Peltier
Peltier Technical Services, Inc., Copyright © 2009.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.


Once again, I rely on Chandoo for inspiration for a charting tutorial. In Select and Show One Chart from Many he shows how to let a user choose which of several charts to show, in an interactive display. He uses data validation to enable the user to select from a finite list of charts, and uses a little-known image linking trick in Excel to show the selected chart. Basically, selecting an item changes a dynamic range so it refers to the range beneath the selected chart, and the picture is linked to this dynamic range.

Dynamic Final Report

This linked-picture trick is related to Excel’s Camera tool, which means two things. First, it’s pretty cool. Second, using it more than a few times will consume resources and slow down the workbook’s response. If you are linking to one picture of many, this is the way to do it, but if you merely want to show different set of data in your chart, it’s more than you need. In this post I will show you an easy and resource-friendly way to achieve the same effects in your dynamic report.

The Report Layout

I’ve set up my report as shown below. Cell F2 contains the selected quantity to be plotted, and I’ve named the cell “WhichChart”. The original data is in B17:E25, and a second data range linked to the first is in B28:E36. The borders around parts of the range B28:E36 show the chart source data range of the working chart, which I will discuss shortly.

Dynamic Report Layout

One or both of the data ranges can be moved to a different place on this sheet, or onto another sheet, so that the focus is on the chart itself.

Data Selection

To make the selection of a chart more flexible, I changed the data validation list source of cell F2 (”WhichChart”) so it refers to the range C17:E17 rather than a hard-coded list (see the dialog below). This way, if I change one of the headers, I don’t need to update the data validation list.

Dynamic Report Data Validation

I generally prefer using a dropdown control or a listbox. A dropdown always shows the drop down arrow icon, so the user knows he can choose something even when the cell is not selected. A listbox shows all options without having to go to all the trouble of dropping down a list. But data validation is pretty easy to use, so it’s really a matter of choice.

The Dynamic Chart

I then constructed a chart that contained all of Chandoo’s data and the formatting from Chandoo’s three charts. I used B18:B25 for the category (X-axis) labels, C17:E17 for the series names, and C18:E25 for the series Y data. To make the chart title dynamic, I selected the title, typed = in the formula bar, then selected the range C17:E17, and pressed Enter. The chart title then displayed the formula =Report!$C$17:$E$17. When multiple cells are selected like this, Excel concatenates the cell values, inserting a space between non-blank items.

Dynamic Report Original Chart

The Dynamic Data

The second data range is linked to the original data, with a twist. It compares the column header to the selection in F2 and shows or hides the column as appropriate. I selected the range C28:E36 with C28 the active cell, entered this formula, then pressed Ctrl+Enter to enter the formula into the entire selected range:

=IF(C$17=WhichChart,C17,"")
 

This hides the headers and Y data for the non-selected column of data. I changed the source data of the chart so that B29:B36 (purple outline) is used for the category (X axis) labels, C28:E28 (green outine) for the series names, and C29:E36 (blue outline) for the series Y data. I also changed the title link formula to =Report!$C$28:$E$28. The outline colors correspond to the colors that Excel highlights these ranges when the chart’s plot area or chart area is selected. When Sales is selected, the data range looks like this (with only the Sales column displayed):

Dynamic Report Data

and the chart looks like this:

Dynamic Report Intermediate Chart

Final Touches

This isn’t quite perfect yet, but it’s easy to finish. First, apply a custom number format of 0;;; to the data labels in the chart, so the zero values (corresponding to the blank cells) are not shown. Second, format any one of the series in the chart so that it has an overlap of 100, so that all columns overlap, and there is no horizontal space wasted for columns with no data. Here is the finished chart:

Dynamic Final Report

Download this dynamic chart (in a zipped workbook).

Possibly Related Posts:

Bookmark and share this entry:
  • Digg
  • del.icio.us
  • Facebook
  • Technorati
  • TwitThis
  • StumbleUpon
  • Google
  • Reddit
  • MySpace
  • Slashdot
  • LinkedIn
  • Yahoo! Buzz

Comments

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.

Read the PTS Blog Comment Policy.


Comment from Robert
Time: Thursday, November 6, 2008, 11:42 am

Jon,

very nice trick. Thanks for sharing.

I found an Excel 2007 oddity though. The technique itself is working fine with Excel 2007 as well. But referring to line 28 in the chart title has a strange effect: It works fine for the first item, but shows ‘320 Expenses 208′ for the second and ‘320 112 Profit’ for the third, i.e. the title of the columns accompanied by the values in the last(!) row of the other two data sets.

If you are using a textbox instead of the chart title, Excel 2007’s behavior is different but odd again: ‘Sales’ is displayed correctly, for the other 2 columns the text box seems to be empty.

You can easily resolve this by linking the chart title to input cell F2.

What do you think? Another bug in Excel 2007?


Comment from Jon Peltier
Time: Thursday, November 6, 2008, 11:52 am

Hi Robert -

So Excel 2007 is making things interesting again. I’ll have to take a look. you’ve applied SP1, haven’t you? That service pack fixed a lot of little annoyances with charts.


Comment from Robert
Time: Thursday, November 6, 2008, 12:05 pm

Jon,

yes, I have Microsoft Office Professional 2007 and 2007 Microsoft Office Suite Service Pack 1 (SP1).

I guess this is an ‘unfixed little annoyance’…


Comment from Jon Peltier
Time: Thursday, November 6, 2008, 12:29 pm

Robert -

In the spring, we’ll see another service pack, so the annoyance factor might go down. of course, SPs only reduce total annoyance incrementally, and you have to wait for a whole new version for large changes in annoyance. (Note that I didn’t say “large reductions”: the change from 2003 to 2007 was a “large increase”.)


Comment from Andrew
Time: Thursday, November 6, 2008, 4:24 pm

I also tried the Chandoo version and I wasn’t able to link a picture to a cell in 2007.
I have SP1 and I tried to do it in 2003 and it worked just fine. Is there a special trick for linking a picture to a cell on 2007?


Comment from Jon Peltier
Time: Thursday, November 6, 2008, 4:41 pm

Andrew -

I just tried, using the tried and true technique that has worked since Excel was invented in the late 1800s, and I could not link a newly inserted picture to a range of cells.

Here’s the two versions of the trick:

1. Use the camera tool to copy the range beneath a chart and then paste it.

2. Select and copy the range beneath a chart, then use Paste Special > As Picture > Paste Picture Link.

Both of these result in a picture which has a link to a range. By the way, it’s not necessary to use a single cell for this. You can use any contiguous rectangular range.


Comment from Simon Wilson
Time: Tuesday, December 9, 2008, 7:07 am

I have a similar but different requirment in that I’m trying to build an auto exceptions report based on RAG status of KPIs.

So if the RAG status is R or A, I want it to appear in the report, if it’s G, I don’t want it to appear.

The graphs are already built in a separate worksheet named “graphs”, and I want them to appear in another called “Exceptions Report”

Any ideas?


Comment from Jon Peltier
Time: Tuesday, December 9, 2008, 8:53 am

Do you mean you have separate charts with only one series, or do you want to be able to control which two of three series appear in a single chart?

The first of these requires a different approach altogether, while the second is covered on my web site in Chart by Combo Box or Checkbox.

Write a comment





Subscribe without commenting

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