Using Check Box to turn on/off lines in a graph

Pigmy

New Member
Joined
Mar 3, 2010
Messages
24
I'm developing a performance dashboard where I show the weekly output from a range of machines. I want to let the user decide if they want to overlay the graph with the machine shop average using a check box. So, I have the formula for machine_1 and the shop_average as 2 separate defined names. In normal circumstances, the graph will just plot the one line, for machine_1. When they check the box, the graph overlays the shop_average.

I've set the check box up and using the True/False that comes from that I can change the values of the shop_average name, however it will always show up on the graph. My current thinking is to set these values to 0 so the line coincides with the axis but this is really clunky. I'd really like to turn the line on and off using the check box. Any ideas?

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can hide the row / column with the data in it which prevents the line for that series being shown on the chart.
 
Upvote 0
Thanks Teeroy - you're a genius. Such a simple solution. I'm going to use a little module to do this - or am I over thinking things again?
 
Upvote 0
If you are using ActiveX CheckBox Controls then you can use the events to do this.

In the sheet code module (that the CheckBox is on) use something like:

Code:
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
    Rows(2).Hidden = True
Else
    Rows(2).Hidden = False
    End If
End Sub
 
Upvote 0
Rather than using code, use formulas.

For example, let the machine_1 data be in B2:B10, and the shop_average data in C2:C10.

Use cell D12 as the checkbox linked cell.

In D2 enter this formula and fill it into D3:D10:

=IF($D12,C2,NA())

Use the data in B2:B10 and D2:D10 for your chart. If the checkbox is checked, the values in D2:D10 will be plotted; if the checkbox is unchecked, the #n/a values in D2:D10 will not be plotted.

The legend will still have an entry for shop_average. But if you label the series and delete the legend, this will not matter. Apply a label to the last point of each series using the Series option.
 
Upvote 0
@Jon Peltier, although hiding via an event does give you a slight overhead for the code execution I tend to prefer it as it hides the label as well.
 
Upvote 0
If a point has a data label, and that point is not plotted because of a #N/A value, the data label is not shown.

In general, solutions that don't rely on VBA are more reliable.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top