Interactive Charts with Checkboxes and Formulas
by Jon Peltier
Tuesday, March 31st, 2009
Peltier Technical Services, Inc., Copyright © 2012.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
An interactive dashboard by definition includes mechanisms for users to control aspects of the display. There are many ways to accomplish this. In Interactive Charting by Combo Box or Checkbox I wrote about using checkboxes to do this. That used a very simple example, which I will explore further in this article.
There are a couple of ways to achieve this interactive control. There is an easy method that relies on worksheet formulas to alter the contents of the source data range of each series, and there is a more involved technique that uses VBA to programmatically adjust the chart’s source data. This post will describe the approach that uses worksheet formulas.
Checkboxes and Worksheet Formulas
Start with a column chart that includes all of the series you will allow the user to select from (A, B, and C in this example). Add a checkbox from the Forms toolbar for each series.

This works as well for a line chart, though the formulas have to be different for line and column charts.

The data range is shown below. The original source data is in J3:M8, and the three checkboxes link to the three cells in K1:M1.
There are two calculated ranges below the original data range. The category labels have simply been copied from the original range, but the other data is linked using worksheet formulas.
For the first calculated range, select K10:M15 so K10 is the active cell, enter
=IF(K$1,K3,"")
then hold CTRL while pressing ENTER to fill the formula into the entire selected range.
For the second calculated range, select K17:M17 so K17 is the active cell, enter
=IF(K$1,K3,"")
then hold CTRL while pressing ENTER to fill the formula into the entire selected range. Then select K18:M22 so K18 is the active cell, enter
=IF(K$1,K4,NA())
and again hold CTRL while pressing ENTER to fill the formula into the entire selected range.

If the Series B checkbox is unchecked, L1 is FALSE, so L10:L15 appear blank, L17 also appears blank, and L18:L22 contain #N/A.

The source data range for the column chart has been changed from J3:M8 to J10:M15. The data for Series B appears blank due to the “” in the formulas, which Excel treats as zero. The bars for Series B have a height of zero, so they don’t appear, and the legend entry for Series B is “”, so it doesn’t appear.

There is still a gap between the bars for Series A and Series C where Series B fits. There also is still a legend key for Series B, which is the unlabeled orange square between the green and blue squares. The legend can be hidden, but then another means is needed to identify the series in the chart.
We don’e want to use “blanks” in the source data for the line chart. Since the “” are interpreted as zero values, the line and markers for Series B lies along the horizontal axis, where Y=0. The legend entry for Series B displays no label, but the legend key still appears (the red bos and line).

For a line chart, use the range J17:J22 as the source data range. This uses #N/A instead of “” to indicate undisplayed values, so the line and markers for Series B don’t even appear in the chart. We still have that pesky unlabeled legend key, though.

It would be nice to use the same data range for both line and column charts, but the #N/A error does not preclude plotting a point in a column chart. The value is zero as in a line chart, but if you put value labels on the points, the result is a label that says “#N/A”. There is no fancy trick using number formats to hide the error.

Using the range with apparent blanks results in labels of “0″ at points corresponding to apparent blanks.

Using a custom number format of “0;;;”, we can suppress the display of any label except positive numbers (and errors).

What happens if the user gets excited and unchecks all of the boxes? The data ranges respond as expected:

And the column chart and line chart both show no data, with unlabeled legends.


CheckboxAndFormula.zip is a zipped workbook which you can download to illustrate this technique.
Checkboxes and VBA
In the next article, I will show how to use VBA in conjunction with the checkboxes to control a column or line chart with a single worksheet range and no formulas, while avoiding gaps for missing columns in the column chart and also avoiding unlabeled legend entries.
Related Posts:
- Interactive Charts with Checkboxes and VBA
- Physics Lesson
- Gas Prices – Interactive Time Series
- Easier Interactive Multiple Line Chart
- Interactive Multiple Line Chart
- Chart Event to Highlight a Series
Posted: Tuesday, March 31st, 2009 under Dynamic Charts.
Comments: 11
Comments
Comment from Bernard Lebelle
Time: Tuesday, March 31, 2009, 11:37 am
Another brilliant way of tweeking Excel. Look forward for a practical implementation on a real dashboard
Comment from Tim Mayes
Time: Thursday, April 2, 2009, 12:57 am
Jon, I’ve been playing around with something very similar to this for awhile now. I’ve been using defined names for the ranges, where the name is either the range that contains the data, or a blank column. The choice is made depending on the value of the cell link from the checkbox. Works great, except, as you mention, the legend entry remains.
For this project, I’m trying very hard to avoid using VBA so I’d rather not use your clever technique from the next post. Is there any non-VBA method of making the legend entry appear or disappear? I can’t think of anything short of just not showing a legend, or deleting the entry for the one series that I want to toggle on or off. That will work for me, but it isn’t ideal and I may just give up and use VBA.
Comment from Jon Peltier
Time: Thursday, April 2, 2009, 5:39 am
Tim -
To change the legend, other than the text shown in the legend entry), you need more than worksheet formulas. You either have to do it manually or using VBA.
You could apply a data label to each series, and when the series isn’t visible, neither is the label. This approach eliminates the need for a legend.
Comment from Tim Mayes
Time: Thursday, April 2, 2009, 11:53 am
Thanks Jon, the data label is the perfect solution. I should have thought of that.
Comment from Jon Peltier
Time: Thursday, April 2, 2009, 2:08 pm
Tim: Next time you will.
Comment from Leonardo
Time: Monday, April 6, 2009, 8:41 am
Hi Jon,
Dynamic Charts are great. I however have a problem currently where the Data Series doesn’t allow me to enter a named range in Excel 2007. I even tried to put it in with VBA but still no joy as well as in the SERIES function. The named ranges are correct, it just seems like Excel 2007 doesn’t support it any more? Does it possibly have something to do with SP’s that I need to install?
Comment from Jon Peltier
Time: Tuesday, April 7, 2009, 5:49 am
Leonardo -
This is still supported. Two hints:
Make sure you qualify the name with the worksheet name. I find the easiest way to get this right is to create my chart with regular data, so the values range is represented by something like =’Data Sheet’!$B$2:$B$100, and replace everything after the exclamation point with the name.
In Excel 2007, there are problems if the name of the named range begins with “Chart”. For example, you can’t name a range ChartData, but you can name it ChtData.
Comment from Leonardo
Time: Thursday, April 9, 2009, 2:52 am
Jon,
Thanks a lot. The inclusion of the Sheet Name did the trick when defining the Data Series on the chart.
I will keep the second hint in mind as well for future. Thanks, you’re a legend!
Comment from Malcolm
Time: Thursday, May 28, 2009, 8:59 am
I have been able to have the legend names appear/disappear if based on the state of the checkboxes; is there a way to also have the legend colors do the same? For example, where you state, “Using a custom number format of “0;;;”, we can suppress the display of any label except positive numbers (and errors).”, can the Series B orange box also disappear?
Comment from Jon Peltier
Time: Thursday, May 28, 2009, 9:56 am
Malcolm – This can be done using VBA, but not through formulas and worksheet tricks. If you set the sheet up so that you can hide a row using an autofilter, then by default data in the hidden cells will be hidden from the chart, but this means that the chart series after the hidden one will assume the formatting of the hidden series.
Comment from Mike
Time: Monday, October 31, 2011, 10:50 am
What a great idea! Thanks so much for this. This was a big help to me. I’m an Excel user of moderate skill, but thanks to you my skillset is increasing.
THANKS!






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.