Select Data to Display in an Excel Chart With Option Buttons

The Problem

A member of the MrExcel forum wanted to know about using form controls to select columns from a data table to populate a graph. Essentially he wanted his users to be able to choose between two charts, one comparing their scores to district and regional scores, the other comparing their scores to the top 20%. This is a retelling of my suggested approach to his question.

Here is some dummy data I used for his problem, and a chart showing all of the data.

Data and Preliminary Line Chart

My suggested approach will add some columns (F:I) to the existing data range with formulas that show or don’t show data based on which of two option buttons is selected, and my chart will use all of this data. When the formulas don’t show the values, they will not appear in the chart.

The Data

The extended data range is shown below. At first the formula in cell F2 (and copied into the entire range F2:I13) is simply

=B2

To give the user a choice, add two option buttons and label them Chart A and Chart B. Right click on one of them (doesn’t matter which) and select Format Control, and on the Control tab, click in the Cell Link box, and select cell K1. This cell shows which of the buttons is selected, 1 or 2.

Extended Data and Option Buttons

You don’t need to show all of this to the user. You could put the chart and option buttons on the active sheet, and all of the data (and the option button linked cell) can go onto another sheet, and you can hide this other sheet if you want. Or you can place the original data on the same sheet as the chart and option buttons, and the formulas onto another sheet, a hidden sheet if desired. You could replace the two option buttons with one listbox that shows both options; the linked cell works the same way.

The Chart

Set up the chart first, before adjusting the formulas to show the result of the option button selection.

Select A1:A13, then hold Ctrl while selecting F1:I13, and insert a line chart.

Preliminary Line Chart

Delete the legend, because it will always show all series, even if some don’t appear because of the formulas. Instead, label the last point in each series with the series name, and use label text that matches each series color. This is more user-friendly than using a legend, anyway. (I also shortened the axis tick labels so they could all be displayed horizontally.)

Cleaned Up Line Chart

The Formulas

Now adjust the formulas. Keep the formulas in column F the way they are, since this series appears whichever option is selected. The formula in G2 (copied into G2:H13) is

=IF($K$1=1,C2,NA())

This means if the first option button is selected, show the corresponding value, otherwise show #N/A. #N/A isn’t plotted in a line or scatter plot.

Similarly the formula in I2 (and filled into I2:I13) is

=IF($K$1=2,E2,NA())

That is, if the second option button is selected, show the value, otherwise show #N/A.

The Finished Product

Here is the data and chart if the Chart A option button is selected:

Data and Chart 'A'

Here is the data and chart if the Chart B option button is selected:

Data and Chart 'B'

You can download a sample workbook by clicking on this link: MrExcelOptionButtonChart.xlsx.

Peltier Tech Chart Utility

Floating Bars in Excel Charts

Floating bars can be used to plot many types of data sets. (“Bars” in this usage means “bars”, as Excel calls horizontally oriented bars, as well as “columns”, as Excel calls vertically oriented bars.) In a waterfall chart, floating bars (usually vertical) show how contributing factors affect a cumulative total. In a Gantt chart, horizontal floating bars along a horizontal date scale help program managers plan task start and end dates and durations, and track progress towards completion of these tasks. Floating bars can be useful to show running highs and lows in a data set, such as daily high and low temperatures, stock prices, diastolic and systolic blood pressure readings, etc.

There are numerous ways to create floating bars in an Excel chart. There are so many ways that I should write more than one post, but I’m going to cram them all into this one. I’ve divided the techniques into the following:

  • Stacked Column and Bar Charts
  • Line Chart Tricks
  • Error Bars
  • XY Chart Line Segments

Stacked Column and Bar Charts

Stacked column and bar charts are probably the most obvious way to create floating bar charts. This approach is pretty flexible, and allows individual floating bars to be formatted differently, but will require some calculations to get the bars to appear as desired.

Stacked Column Charts (Vertical Bars)

This tutorial will show simple floating columns, stacked floating columns, floating columns that span the horizontal axis, and overlapping floating columns, all using stacked column charts.

Floating Columns

In the data set below, there are several high and low values for the categories in a column chart. The clustered column chart shows the values we want to highlight: we want a floating column to connect each low value to its corresponding high value.

We achieve this by inserting a column in the worksheet which has a simple formula to calculate the difference between high and low (“Delta” in the table below). Adjusting the data range and changing from clustered to stacked columns shows all we need. The floating column is resting on top of the Low value column.

A little formatting gives us all we need. The Low series is formatted to be invisible: no border and no fill. The vertical axis has been rescaled to zoom in on the data and remove some of the white space below the floating bars.

You can change the relative width of the columns and gaps between by selecting them and changing the Gap Width property; a Gap Width of 100 means that the gap will be 100% as wide as a bar. I like to use gap widths of 50% to 100%, and I used 75% in most of the charts here.

With this technique, each column can be selected (it may take two single clicks) and formatted independently of the rest, for purposes of highlighting one or more specific values.

The gold and purple colors above may show extreme highlighting, and were selected to clearly show the different colors. In general, subtle highlighting, like the slightly darker shade of point C or the outlined column of point F are usually sufficient.

Stacked Floating Columns

The stacked column chart allows multiple items to be stacked, since each floating column rests on the lower columns. This table and chart show low, medium, and high values.

Insert two columns for the two sets of calculations of floating column heights, and plot these with the minimum value.

As before, format the lowest column to be invisible, and adjust the axis scale, if desired.

As before, individual columns can be formatted independently of the others.

Floating Columns Crossing the Horizontal Axis

If you want to show floating columns that span negative and positive values, you will encounter problems, as shown by this sample data. It all looks fine when we examine the unstacked columns that show the minimum and maximum values.

However, when we plot the minimum values and stack the differences on top, we see that the stacking doesn’t work the way we would have liked. Excel plots columns with negative values below the X axis and columns with positive values above the X axis. Even though the Delta begins below the X axis, the Delta column has a positive value, and is plotted starting at zero or at the top of the minimum, if that value is positive.

Our simple formulas are not adequate, and we need a different approach. We’ll add three columns to the data sheet: one for the blank columns on which the floating columns will rest, one for whatever part of the floating column is positive (above the X axis), and one for whatever part of the floating column is negative. Using pseudo-references, the formulas we need are:

Blank:  =IF(High<0,High,IF(Low>0,Low,0))
  Pos:  =IF(High>0,High-MAX(Low,0),0)
  Neg:  =IF(Low<0,Low-MIN(High,0),0)

When we plot these values, we get the floating columns spanning the ranges we expect. Note that the floating columns may consist of two pieces, one (orange) below and one (blue) above the X axis, if necessary separated from the axis by the blank series (shown gray in the chart below).

As always, format the blank series to be blank (no border and no fill), and format the floaters as desired.

As before, individual floating columns can be formatted independently; the positive and negative portions can be formatted the same or differently.

Overlapping Floating Columns

You may want to show two sets of floating columns. For example, you may want to compare high and low temperatures for a set of dates with the average historical high and low temperatures for those dates. The way to handle this is to have one set of data on the primary axis, and the other set on the secondary axis.

The table and chart below show two sets of high and low values. The blue will eventually be shown on the primary axis and the orange on the secondary.

Insert two columns in the sheet, to capture the differences between high and low in the two sets of data. Here are the low and delta of each set in a stacked column chart.

Here is the same stacked column chart, with the orange series moved to the secondary axis. Each axis has its own Gap Width setting. Here I’ve used 50 for the primary axis (blue columns in back), and 150% for the secondary axis (orange columns in front).

More formatting: Hide the low columns (no border or fill) and adjust the Y axis. Also, delete the secondary vertical axis and if present the secondary horizontal axis. The chart will keep the series for each axis separate (so they have separate gap widths and so they don’t go stacking on each other), but will plot them on the primary axis scales.

Individual columns can always be formatted separately.

Stacked Bar Charts (Horizontal Bars)

The techniques described above for Vertical Column Charts work the same for Horizontal Bar Charts. This tutorial will show simple floating bars, stacked floating bars, floating barsthat span the vertical axis, and overlapping floating bars, all using stacked bar charts.

Floating Bars

In the data set below, there are several high and low values for the categories in a bar chart. The clustered bar chart shows the values we want to highlight: we want a floating bar to connect each low value to its corresponding high value.

To get the vertical axis labels in your chart to be in the same top-to-bottom order as in the worksheet, follow the approach described in Why Are My Excel Bar Chart Categories Backwards? and in Excel Plotted My Bar Chart Upside-Down.

Note also that in an Excel Bar Chart the vertical axis is the X axis (for the independent variable), and the horizontal axis is the Y axis (for the dependent variable). This confuses a lot of people, so I usually stick to “horizontal” and “vertical” instead of “X” and “Y”.

We achieve this by inserting a column in the worksheet which has a simple formula to calculate the difference between high and low (“Delta” in the table below). Adjusting the data range and changing from clustered to stacked bars shows all we need. The floating bar is resting to the right of the Low value bar.

A little formatting gives us all we need. The Low series is formatted to be invisible: no border and no fill. The horizontal axis has been rescaled to zoom in on the data and remove some of the white space to the left of the floating bars.

You can change the relative width of the bars and gaps between by selecting them and changing the Gap Width property; a Gap Width of 100 means that the gap will be 100% as wide as a bar. I like to use gap widths of 50% to 100%, and I used 75% in most of the charts here.

With this technique, each bar can be selected (it may take two single clicks) and formatted independently of the rest, for purposes of highlighting one or more specific values.

Stacked Floating Bars

The stacked bar chart allows multiple items to be stacked, since each floating bar rests on the lower bars. This table and chart show low, medium, and high values.

Insert two columns for the two sets of calculations of floating bar lengths, and plot these with the minimum value.

As before, format the lowest bar to be invisible, and adjust the axis scale, if desired.

As before, individual bars can be formatted independently of the others.

Floating Bars Crossing the Vertical Axis

If you want to show floating bars that span negative and positive values, you will encounter problems, as shown by this sample data. It all looks fine when we examine the unstacked bars that show the minimum and maximum values.

However, when we plot the minimum values and stack the differences on top, we see that the stacking doesn’t work the way we would have liked. Excel plots bars with negative values to the left of the X axis and bars with positive values to the right of the X axis. Even though the Delta begins to the left of the X axis, the Delta bar has a positive value, and is plotted starting at zero or at the right end of the minimum, if that value is positive.

Our simple formulas are not adequate, and we need a different approach. We’ll add three columns to the data sheet: one for the blank bars on which the floating bars will rest, one for whatever part of the floating bar is positive (above the X axis), and one for whatever part of the floating bar is negative. Using pseudo-references, the formulas we need are:

Blank:  =IF(High<0,High,IF(Low>0,Low,0))
  Pos:  =IF(High>0,High-MAX(Low,0),0)
  Neg:  =IF(Low<0,Low-MIN(High,0),0)

When we plot these values, we get the floating bars spanning the ranges we expect. Note that the floating bars may consist of two pieces, one (orange) to the left of and one (blue) to the right of the X axis, if necessary separated from the axis by the blank series (shown gray in the chart below).

As always, format the blank series to be blank (no border and no fill), and format the floaters as desired.

As before, individual floating bars can be formatted independently; the positive and negative portions can be formatted the same or differently.

Overlapping Floating Bars

You may want to show two sets of floating bars. For example, you may want to compare high and low temperatures for a set of dates with the average historical high and low temperatures for those dates. The way to handle this is to have one set of data on the primary axis, and the other set on the secondary axis.

The table and chart below show two sets of high and low values. The blue will eventually be shown on the primary axis and the orange on the secondary.

Insert two columns in the sheet, to capture the differences between high and low in the two sets of data. Here are the low and delta of each set in a stacked bar chart.

Here is the same stacked bar chart, with the orange series moved to the secondary axis. Each axis has its own Gap Width setting. Here I’ve used 50 for the primary axis (blue bars in back), and 150% for the secondary axis (orange bars in front).

If you used the Upside-Down-Bar-Chart trick to plot the primary vertical axis labels in the same order that they appear in the worksheet, you’ll have to display the secondary vertical axis and apply the same trick to it.

More formatting: Hide the low bars (no border or fill) and adjust the Y axis. Also, delete the secondary horizontal axis and if present the secondary vertical axis. The chart will keep the series for each axis separate (so they have separate gap widths and so they don’t go stacking on each other), but will plot their values using the primary axis scales.

Individual bars can always be formatted separately.

Line Chart Tricks

Excel’s line charts have a few built-in features that can be used to generate floating columns. These include Up-Down Bars and High-Low Lines, which can be combined to create Open-High-Low-Close (OHLC) Stock Charts, and also Drop Lines. Being tied into line charts, these features can only be used to generate vertical floating bars.

Up-Down Bars

Up-Down Bars connect the values of a chart’s first line chart series and last line chart series with floating bars. There are actually two sets of bars: Up Bars, which connect a lower first value to a higher last value (the value goes Up), and Down Bars, which connect a higher first value to a lower last value (the value goes Down).

Floating Columns

For simple floating bars, you need to plot two data series in a line chart.

In Excel 2013, click the Plus icon next to the chart, and check the Up-Down Bars box; alternatively, on the Chart Tools > Design ribbon tab, click the Add Chart Element dropdown, and select Up-Down Bars. In Excel 2007 or 2010, on the Chart Tools > Layout ribbon tab, use the Up/Down Bars dropdown.

The chart below specifically has Down Bars, since all of the values in the last series are lower than all those of the first series.

Unlike the Stacked Column Chart technique, we need to carry out no calculations to determine how tall the floating bars have to be, and we don’t need a hidden set of bars on which to balance the floating bars.

Now apply a little formatting. Format the lines to have no markers and no lines, and give the up-down bars a suitable fill color.

You can change the relative width of the up-down bars and gaps between by selecting them and changing the Gap Width property of one of the line chart series; a Gap Width of 100 means that the gap will be 100% as wide as a bar. I like to use gap widths of 50% to 100%, and I used 75% in most of the charts here.

Mixed Formats: Up vs. Down

You can’t format individual up-down bars with their own colors, but since there are Up Bars and Down Bars, you can at least format some with one color and the rest with another color.

In the data below I’ve switched the First and Last values for points C and D. The line series cross, so the Last series is greater than the First for these points.

When Up-Down Bars are added, the black Down Bars for most of the points are replaced by Up Bars for points C and D.

In this way we can assign different formats to highlight selected points.

Up-Down Bars: First to Last

As mentioned before, Up-Down Bars connect the first line chart series to the last, ignoring values in between. In this data set, the earlier First and Last series have had intermediate series Second and Third inserted between them.

When Up-Down Bars are inserted, they connect First and Last, ignoring any values of Second and Third that may extend beyond First and Last.

Floating Columns Crossing the Horizontal Axis

When dealing with the Stacked Column Chart technique, if you recall, we couldn’t simply use a floating column to span values below and above the horizontal axis. Let’s try this with Up-Down Bars.

The lines show where we want the bars to appear, and when we add the Up-Down Bars…

… they go where we want. Again, no calculations required.

Overlapping Floating Columns

We can use Up-Down Bars to generate overlapping sets of floating bars, using primary and secondary axis groups. Here are two pairs of values plotted in a line chart. The Blue series are plotted on the primary axis, and the Orange series on the secondary. The secondary vertical axis has been deleted so that all values are plotted along the primary axis.

One of the primary series is selected, and Up-Down Bars are added.

One of the secondary series is selected, and again Up-Down Bars are selected.

The Up-Down Bars are formatted with different colors, and the line chart series are formatted to use different gap widths as well as no lines and no markers.

As before, individual bars can be formatted as Up Bars among a field of Down Bars. In the table below, first and last values have been switched for points C and D for both primary and secondary series. The line chart series cross…

… and the bars have been formatted differently to highlight points C and D.

High-Low Lines

High Low Lines connect the highest and lowest values of a chart’s line chart series using vertical lines. The order of series makes no difference to these lines.

Floating Columns

For simple floating bars, you need to plot two data series in a line chart.

In Excel 2013, on the Chart Tools > Design ribbon tab, click the Add Chart Element dropdown, click Lines, and select High-Low Lines. In Excel 2007 or 2010, on the Chart Tools > Layout ribbon tab, use the Lines dropdown, and select High-Low Lines.

Format the plotted line series with no lines and no markers to hide them, and you’re left with boring black vertical lines.

In classic versions of Excel (2003 and earlier) you had limited ability to format such lines, but Excel 2007 introduced the ability to make the lines pretty much as wide as desired. The high-low lines in the chart below are 13.5 points thick, and look a lot like the floating columns produced by the other techniques above.

These lines can be assigned colors and thicknesses, but are not actually rectangular shapes, so they don’t have both border and fill colors.

High-Low Lines: Highest to Lowest

High-Low Lines work by connecting the lowest and highest values at each category. It doesn’t matter where in the sequence the high or low value occurs. In the data below, the highest (blue) and lowest (red) values are highlighted: they are distributed among the columns of data.

When High-Low Lines are added, they connect high and low, regardless of which series includes the extremes.

Note that no values are located above or below the formatted High-Low Lines.

Floating Columns Crossing the Horizontal Axis

The Stacked Column Chart technique required tricky formulas to allow a floating column to span values below and above the horizontal axis, while the Up-Down Bar approach did not. Let’s try this with High-Low Lines.

The lines show where we want the bars to appear, and when we add the High-Low Lines…

… and format them…

… they go where we want. As with Up-Down Bars, it works easily, no calculations required.

Overlapping Floating Columns

We can use High-Low Lines to generate overlapping sets of floating bars, using primary and secondary axis groups. Here are two pairs of values plotted in a line chart. The Blue series are plotted on the primary axis, and the Orange series on the secondary. The secondary vertical axis has been deleted so that all values are plotted along the primary axis.

A primary axis series is selected, and High-Low Lines are added.

A secondary axis series is selected, and again High-Low Lines are selected.

The High-Low Lines are formatted with different colors and line widths (13.5 and 8 pts), and the line chart series are formatted to use no lines and no markers.

Stock Charts

Up-Down Bars and High-Low Lines were probably introduced into Excel to enable Open-High-Low-Close type Candlestick stock charts. Open and Close are the First and Last series from the Up-Down Bars examples above, and High and Low are, well, High and Low from the High-Low Lines examples. When applied together with the data columns in the appropriate order, simple line charts can be formatted into OHLC charts.

Line Chart Plus

Here is a table with two weeks of stock data and the corresponding line chart.

Add High-Low Lines…

… add Up-Down Bars…

… and do a little formatting to create a candlestick chart. Use no markers or lines for the plotted series, and use your favorite colors and gap width for the Up-Down Bars. I always forget whether black or white bars signify up or down, and green and red make a bad combination for color vision deficient viewers, so I usually use blue for up and red or orange for down.

In “Classic” versions of Excel (97 through 2003), the line chart with High-Low Lines and Up-Down Bars was smart enough to recognize itself as a stock chart type, but since Excel 2007, such a chart only considers itself a line chart.

In Excel 2007 and later you cannot combine a stock chart with any other chart type, so you can’t add another series to show how, say, some market index varies in comparison. But you can make your stock chart using a line chart like I did here, then add whatever index lines you want.

Built-In OHLC

Using the same data set, you can directly insert an OHLC stock chart.

A little formatting, and it’s identical the the line chart stock chart above.

The only difference is that the “official” stock chart can’t be combined with any other data.

Drop Lines

Drop Lines are lines that drop from data points to the horizontal (category) axis in line charts and area charts. Each line or area series in a chart can have Drop Lines, and every point in a series with Drop Lines has a Drop Line. Drop Lines cannot produce floating bars, since they by definition start at the axis, but they are related to these other techniques, and it’s useful to know about them, even if you use them only infrequently.

Column Chart

Here is the simple data and line chart we’ll use for our Drop Lines example.

In Excel 2013, on the Chart Tools > Design ribbon tab, click the Add Chart Element dropdown, click Lines, and select Drop Lines. In Excel 2007 or 2010, on the Chart Tools > Layout ribbon tab, use the Lines dropdown, and select Drop Lines. The lines are thin vertical black lines.

Like any lines in Excel 2007 and later, we have great flexibility in how we want to format Drop Lines. Here I’ve hidden the line series (no markers and no lines) and I’ve given the Drop Lines a width of 13.5 points and a blue/cyan line color, to produce what appears to be a standard column chart.

Error Bars

Line Charts with Error Bars

Line charts can have vertical Error Bars, oriented upwards or downwards of the data points, or both. This technique will work with column and area charts as well, but it’s easier to illustrate with line charts.

Floating Bars

We can use Error Bars with custom lengths as floating bars. Here we have high and low values, shown together in a line chart. There is another worksheet column with formulas that compute the differences (Delta).

We only need one of the line chart series for our Error Bars. We can plot the High values, and use Minus Error Bars for our floating bars (left), or we can plot the Low values, and use Plus Error Bars for our floating bars (right).

To assign custom values for error bars, first add Error Bars (in Excel 2013, use the Plus icon floating beside the chart; in Excel 2007 or 2010, use the Error Bars control on the Chart Tools > Layout tab). Then under Error Bar Values in the formatting dialog or task pane, select Custom and click Select Values. In the dialog, click in the Plus or Minus box, and select the range of cells with the Error Bar values. If you are only using one of the boxes, you have to explicitly type a zero in the other box, or Excel will not recognize your selection. Stupid Excel.

Hide the line chart series (format with no lines or markers), and format the Error Bar lines to use No End Caps, and appropriate width (here I’ve used 13.5 points) and line color.

Stacked Floating Bars

Here are High, Mid, and Low values along with the computed differences between adjacent points (Upper and Lower). We want stacked floating bars showing the distance between Low and Mid and between Mid and High.

“Aha!” you say, “I’m way ahead of you this time.” Plot the Mid series with Plus and Minus Error Bars (below left), then format the Error Bars as above (below right). But wait, the Plus and Minus Error Bars cannot be independently formatted?

Too bad, but it’s not a big deal. We just need two series, one for each independently formatted set of Error Bars. Here, I’ll plot the High and Low series.

I’ll add Minus Error Bars to the High series, then Plus error bars to the Low series.

Then I’ll hide both series and format the Error Bars.

Floating Columns Crossing the Horizontal Axis

When using Stacked Column Charts to generate floating bars, if you recall, we couldn’t simply use a floating column to span values below and above the horizontal axis. But Up-Down Bars and High-Low Lines didn’t care if they crossed the axis. Let’s try this with Error Bars, using the same High and Low values as before.

So we try the High series with Minus Error Bars, and the Low series with Plus Error Bars. Both allow the Error Bars to cross the category axis.

Format away.

Error Bars as Drop Lines

Error Bars can also be used to create Drop Lines. Here’s a simple line chart using the Drop Lines data from above.

Instead of adding Drop Lines, we can add Error Bars, choose the Minus direction, and a Percentage Value of 100.

No lines and markers for the data series, no end caps but thick lines and a nice line color for the Error Bars.

XY Scatter Charts with Error Bars

As with the line charts in the preceding section, XY scatter charts can support vertical Error Bars. They can also support horizontal Error Bars. Every trick that works with line chart vertical Error Bars will also work with XY scatter chart vertical and horizontal Error Bars.

Vertical Floating Bars

Okay, we already know it’s going to work, but let’s run through the exercise for completeness. Here is the same High and Low data as before, with numeric rather than alphabetic X values.

Plot the High series with Minus Error Bars or the Low series with Plus Error Bars…

… a little formatting, and it’s the same as with the line chart Error Bars.

Horizontal Floating Bars

Plot the same data, but exchange X and Y in the chart.

Plot the High series with Minus horizontal Error Bars or the Low series with Plus horizontal Error Bars.

The same as before, but horizontal.

Vertical Drop Lines

We can use vertical error bars on an XY scatter chart to create drop lines. Same data as before, but in a scatter plot.

Add Minus Error Bars, using the Percentage Value option, and 100%.

Hide the plotted series and format the Error Bars.

This is the answer to two common Excel-related forum questions:

  • How do I get Drop Lines on my scatter plot?
  • How can I get a column chart on a value X axis?

Horizontal Drop Lines

Taking the previous data, but switching X and Y…

Add horizontal Minus Error Bars, using the Percentage Value option, and 100%, then hide the plotted series and format the Error Bars.

XY Chart Line Segments

A very powerful technique for creating floating bars is using XY chart series line segments. You can make vertical and horizontal floating bars, but you are not constrained to these simple orientations. You can position endpoints of your bars pretty much anywhere in you chart, so the possibilities are limitless. In addition, line segments can be independently formatted, even within the same series of points.

I will use simple examples to illustrate the technique, then set you free.

Floating Columns and Bars

Here are plots showing the same High and Low values for vertical and horizontal floating bars.

XY chart segments connect points in the same series, not in different series as in several of the techniques covered so far. So we need to arrange the data to plot points in one series, not two.

We could use that data, but then we’d have to format the in-between (slanted) segments to use no line color. Pretty tedious after the second or third line segment. But if we insert a blank row between each pair of values, Excel will not plot a line segment across the gap, so formatting will be easy.

As with the previous techniques using thick formatted lines, we’ll start with out XY scatter chart, and thicken up the lines. The vertical lines are 13.5 points, the horizontal lines, 10.5 points. But we’ve hidden the markers; why are there circles at the endpoints?

It turns out that Excel’s richly formattable lines have three different “Cap Type” styles. I’ve illustrated them here with small red markers to illustrate their appearance. The Round Cap style has a circular end shape extending beyond the endpoint of the line segment, where the marker is at the center of the circle. The Square Cap style has a square end end shape extending beyond the endpoint of the line segment, with the markers at the center of the square. And the Flat Cap stops exactly at the end of the segment, with the line squared off right at the marker.

We didn’t have to worry about this with the Error Bars, Drop Lines, and High-Low Lines, because their default “Cap Type” is Flat Cap.

The default “Cap Type” for chart series line segments is Round Cap, which makes for nice-looking polygonal plotted lines. But for floating bars, we most likely will want to use the Flat Cap style.

Here are floating bars using vertical and horizontal XY segments and the Flat Cap style.

We can select individual line segments (click once to select the entire series, and again to select the particular line segment), and format them independently of the others.

Stacked Floating Columns and Bars

Here is our stacked floating bar data, plotted as separate series for vertical and horizontal floating bars.

Here is the same data rearranged to facilitate XY series line segments for vertical and horizontal floating bars, including the blank rows between pairs of points.

Hide the markers and fatten up the lines, and we’ve got stacked floating bars.

As before, individual bars (line segments) can be formatted independently of the rest.

Summary

Here is a summary of the Floating Bar techniques discussed in this article.

Most techniques provide vertical bars, a couple horizontal bars, and XY Scatter Line Segments alone produce bars at any orientation.

A few techniques provide actual rectangular bars, which have a border and fill, while many approximate the appearance of a rectangle with thick line segments.

Some techniques allow individual bars in a set to be formatted independently, and some allow easy creation of stacked bars through the use of multiple series.

Stacke column and bar charts do not permit floating bars to cross the category axis, at least not without using tricky formulas to split bars into positive and negative components. The other techniques allow floating bars above, below, or across the axis.

Peltier Tech Chart Utility

Secondary Axis as Percentage of Target

I haven’t posted in quite a while. I have a few long tutorials that I’m working on, but there hasn’t been enough uninterrupted time to get them done.

I’ve also been working on a new edition of my Chart Utility which will run in PowerPoint. This will allow those users who spend most of their time in PowerPoint to run the utility from there, switching to Excel for long enough to select their data, then build their chart as a native PowerPoint chart. I mean, it’s still really an Excel chart, but it will behave as if it were created in PowerPoint (which it was), and the data will sit in its data sheet in PowerPoint. Tentative plans call for the new utility to be released a month and a half ago. I’ll probably release it in stages, starting in a couple weeks.

In the meantime, a customer asked me to help with a certain topic, and I thought it made a great tutorial, so here it is.

Secondary Axis as Percentage of Target

A customer had a stacked chart showing contributions to a fundraising effort by source (below) and wanted to show percentage toward the target. He had sketched something with labels and tickmarks and arrows everywhere, but I thought that was a bit too intrusive and cluttered. Instead I decided to use a secondary axis scale showing the percentage.

Stacked Columns Showing Fundraising Totals

I’ve written before about how Secondary Axes in Charts can be more confusing than enlightening, adding to the cognitive load required to understand a chart. But I’ve also written about Secondary Axes that Work – Proportional Scales, and I’ve showed how to Add Percentages on the Secondary Axis. This is really another illustration of that last tutorial.

The only way to get a secondary axis is to have a series that is plotted on the secondary axis. I modified his data range by adding a series named “Blank” with a value of zero. The chart below is selected, and you can see from the highlighted ranges in the worksheet that it includes all series including the new Blank one. To the right I’ve done some calculations that we’ll be using momentarily. Essentially, given a target of 300 and a primary Y axis maximum of 160, I know that the corresponding secondary Y axis maximum should be 53.333%.
Stacked Columns Showing Fundraising Totals
The charts below show the steps in constructing the improved chart. Left, I moved the Blank series to the secondary axis. Excel added a secondary vertical axis with a scale ranging from zero to one. Center, I deleted the gridlines, and made all three visible axis lines the same medium-light gray color, and gave the vertical axes major tick marks outside of the axis. Right, I rescaled the axes. I hard-coded the min and max of the primary axis to 0 and 160, just so they didn’t change without me knowing it. I set the min and max of the secondary axis to 0 and 53.333%, and changed the number format to Percentage with No Digits.
Stacked Columns Showing Fundraising Totals
Finally I made the chart a little bit taller to allow for a descriptive title. Probably some indication of currency in the primary axis tick labels would also be useful. I also hid the row with the blank data and the columns with my secondary axis calculations, in case the entire sheet would be made public.
Stacked Columns Showing Fundraising Totals

Peltier Tech Chart Utility

Chart Partial Range Between Variable Endpoints

Plotting Part of a Data Range

Excel is pretty handy for collecting, analyzing, and charting lots of data. If you want to plot a subset of your data, you can manually adjust the data range used by the chart. But there are easier ways to select partial data ranges, and to make this selection less tedious than manually adjusting the chart’s data.

Plotting the Entire Range

In the workbook named “MSFT Price.xlsx” (click to download) and its worksheet named “MSFT 5-week” I have a range and chart showing five weeks of Microsoft adjusted closing price data.

Chart Entire Range

The series formula of the chart is:

=SERIES('MSFT 5-week'!$B$1,'MSFT 5-week'!$A$2:$A$26,'MSFT 5-week'!$B$2:$B$26,1)

Recall that the series formula includes the chart data as follows:

=SERIES(Series Name, X Values, Y Values, Plot Order)

and that the series can be edited right in the Formula Bar, just like any other Excel formula.

A commonly asked question is, How can we plot part of this data, based on some kind of lookup? We’ll use a technique known variously as “Names” (the official moniker), “Defined Names”, “Defined Ranges”, and “Named Ranges”. I’ll show three approaches, which increase in complexity but also in ease of use.

Defined Names – By Index

This exercise is in a worksheet named “MSFT By Index”. The data is the same and the chart is nominally the same as above. We’ll use cells E2:E3 to contain the index of the first and last rows of the data range we want to plot. We will count rows in the data range and enter values into these cells.

Dynamic Names by Count

To define names, go to the Formulas tab of the ribbon, click on the Define Name button, and select Define Name… from the dropdown menu.

Define Names

The New Name dialog appears. You can name the name, define its scope to the entire workbook or to one of its worksheets, add a comment, and write a formula which the name refers to.

Define Name Dialog

For the dates in our chart, we will define the following name:

Name: MSFT_Date_Index
Refers To:
=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$2,0):
     OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$3,0)

OFFSET takes three arguments: a reference range, the number of rows down from this reference (up for a negative number of rows), and the number of columns to the right of the reference (to the left for a negative number of columns). OFFSET may take two more arguments: the number of rows high and the number of columns wide the resulting range is; if height and width are not entered, the resulting range is the same size as the reference range.

This OFFSET:

=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$2,0)

indicates the cell $E$2 rows down and zero columns right from $A$1, while this OFFSET:

=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$3,0)

indicates the cell $E$2 rows down and zero columns right from $A$1. Combining the two OFFSETs, separated by a colon, indicates the range bracketed by the two cells.

For the values, we will use this simple OFFSET that returns the prices in the column immediately to the right of the dates defined by MSFT_Date_Index:

Name: MSFT_Close_Index
Refers To:
=OFFSET(MSFT_Date_Index,0,1)

To make the chart dynamic, replace the cell addresses of the X and Y values in the original series formula:

=SERIES('MSFT By Index'!$B$1,'MSFT By Index'!$A$2:$A$26,'MSFT By Index'!$B$2:$B$26,1)

with the names we’ve defined. Here is the series formula as edited in the formula bar:

=SERIES('MSFT By Index'!$B$1,'MSFT By Index'!MSFT_Date_Index,
            'MSFT By Index'!MSFT_Close_Index,1)

Since the names were scoped to the workbook, the worksheet name in the series formula is replaced by the workbook name:

=SERIES('MSFT By Index'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Index,
            'MSFT Price.xlsx'!MSFT_Close_Index,1)

Here is the chart for an arbitrary pair of first and last index values:

Dynamic Names by Count

Adjust the first and last indices in E2:E3, and the chart updates to reflect the new range.

Dynamic Names by Count

This is a bit tedious in practice, since you need to count rows and enter your findings in the index cells. It is not hard to make the process easier.

Defined Names – By Match

This exercise is in a worksheet named “MSFT By Match”. The data and the chart are the same as above. We’ll use cells F2:F3 to contain the first and last dates of the data range we want to plot. Formulas in E2:E3 will determine the index of these dates within the date range, so we can use the same formulas as above for our names. We will enter dates into cells F2:F3 and let Excel calculate the index values in E2:E3, which is a little nicer than counting rows and typing a number.

Dynamic Names by Match
These formulas in E2:E3 determine the where the dates in F2:F3 fall in the overall list of dates:

Cell E2:  =MATCH(F2,$A$2:$A$26,-1)
Cell E3:  =MATCH(F3,$A$2:$A$26,-1)

The last argument (-1) in the functions is needed because the dates in column A are listed in descending order. Omit this argument, or use +1, for data sorted in ascending order. Use zero if the data are unsorted labels.

The name that includes the dates for our chart is:

Name: MSFT_Date_Match
Refers To:
=OFFSET('MSFT By Match'!$A$1,'MSFT By Match'!$E$2,0):
     OFFSET('MSFT By Match'!$A$1,'MSFT By Match'!$E$3,0)

This is the same, except for the sheet name, as in the previous exercise. The corresponding name for the prices should also look familiar:

Name: MSFT_Close_Match
Refers To:
=OFFSET(MSFT_Date_Match,0,1)

The series formula for the dynamic chart looks like this as edited:

=SERIES('MSFT By Match'!$B$1,'MSFT By Match'!MSFT_Date_Match,
            'MSFT By Match'!MSFT_Close_Match,1)

and like this when Excel replaces the sheet name with the workbook name for the workbook-scoped names:

=SERIES('MSFT By Match'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Match,
            'MSFT Price.xlsx'!MSFT_Close_Match,1)

Here is how the chart looks for an arbitrary pair of dates:

Dynamic Names by Match

Adjust the first and last dates in F2:F3, and the chart updates to reflect the new range.

Dynamic Names by Match

It’s much easier to enter dates than to count rows, especially if the overall data range extended beyond the number of rows visible in one screen.

Defined Names – By Combo Box

This exercise is in a worksheet named “MSFT By Combo”. The data and the chart are the same as above. We’ll use combo box controls that let us select the first and last dates of the data range we want to plot. The combo boxes link to cells E2:E3, so we can again use the same formulas as above for our names. Now we’ll use the best method in this article: we’ll select the dates we want using the combo boxes.

Dynamic Names by Match

To add a combo box control, go to the Developer tab, click Insert, then click the Combo Box from the set of Forms Controls. The cursor turns into a shape crosshair; use this to draw the combo box.

Dynamic Names by Combo

If the Developer tab is not visible, you have to change your settings. In Excel 2010 and 2013, click the green File tab, select Options, select Customize Ribbon, and in the long list of tabs on the right, check the box in front of Developer. In Excel 2007, click the big round Office button in the top left of the Excel window, click Excel Options at the bottom of the dialog, then check Show Developer Tab in the Ribbon.

Right click on the combo box, and choose Format Control from the pop-up. Select the input range (the range of dates that you want to appear in the dropdown) and the cell link (where the index of the selected date will appear).

Dynamic Names by Combo
With both combo boxes formatted, defining the names proceeds as above, with essentially the same formulas. The dates:

Name: MSFT_Date_Combo

Refers To:
=OFFSET('MSFT By Combo'!$A$1,'MSFT By Combo'!$E$2,0):
     OFFSET('MSFT By Combo'!$A$1,'MSFT By Combo'!$E$3,0)

The price values:

Name: MSFT_Close_Combo
Refers To:
=OFFSET(MSFT_Date_Combo,0,1)

Here is the series formula as edited to reflect the names:

=SERIES('MSFT By Combo'!$B$1,'MSFT By Combo'!MSFT_Date_Combo,
            'MSFT By Combo'!MSFT_Close_Combo,1)

and adjusted by Excel to show the workbook name for the workbook-scoped names:

=SERIES('MSFT By Combo'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Combo,
            'MSFT Price.xlsx'!MSFT_Close_Combo,1)

Dynamic Names by Combo

Adjust the first and last dates selected in the combo boxes, and the chart updates to reflect the new range.

Dynamic Names by Combo

Peltier Tech Chart Utility

Polar Plot in Excel

Polar Plots

Microsoft Excel offers a number of circular charts, but none of them is usually a particularly good choice for displaying data. You can search this blog for “pie chart” and see numerous examples of badly applied pie charts. If you hunt for “radar chart” or “spider chart” you’ll see a class of charts that’s even more deceptive. A major part of the deficiency of radar plots is that they pretend to show a physical, geographical relationship which isn’t present at all.

Excel Polar Plot

Polar Plots, on the other hand, can be used to map information that has a true geographical component. Ironically, this includes actual radar feedback. The data for a polar plot is given in polar coordinates, which is given as R-theta, where R is the distance from the origin (center of the plot) and theta is the angle from a reference angle, such as north or conversely the positive horizontal axis of overlaid cartesian coordinates.

A Polar Plot is not a native Excel chart type, but it can be built using a relatively simple combination of Donut and XY Scatter chart types. We need to build the grid using a donut chart, then overlay the physical data using applicable XY Scatter chart types.

Preparing the Data

We’ll use a donut chart for the circular grid. The data we need is simple, as shown below. I have 9 columns for the 9 concentric donuts (the smallest donut hole is 10% of the diameter, so this hole plus 9 rings of 10% make 100%). Each ring has 12 segments, so each comprises 30° of the 360° circle of the chart.

Excel Polar Plot Grid Data

Our data is provided in polar coordinates in columns A and B below, where R is the distance from the origin to the data point, and theta is the angle from our reference angle (due north) to the point. These are converted to X and Y in columns C and D. The formula in C2and D2 are:

C2:  =A2*SIN(B2/180*PI())
D2:  =A2*COS(B2/180*PI())

These are filled down to C14 and D14.

Excel Polar Plot Values Data

Making the Chart

To create the grid, select the blue shaded cells in the top table, and insert a donut chart (below left). The default diameter of the donut hole is 75% of the diameter of the whole chart, so all of the rings are scrunched together. Select any of the donuts and press Ctrl+1 (numeral one) to open the Format Series dialog or task pane, and set Donut Hole Size to 10%, the smallest possible value (below right). While you’re at it, shrink the ridiculously large chart title, if you need it at all.

Excel Polar Plot Steps 1 and 2

Format each donut series so it has no fill and uses a thin (0.75 point) light gray (25% gray) border (below left). Our grid is ready for real data.

Select the orange shaded range of XY values in the second table above, and copy. Select the chart, and click the Paste Special button on the Paste dropdown on the Home tab of the ribbon to add the data (below right). The data is added as another concentric donut on the outside of the chart.

Excel Polar Plot Steps 3 and 4

Use the following settings in the Paste Special dialog: Add cells as New Series, Values in Columns, Series Names in First Row, and Categories in First Column.

Paste Special Chart Dialog
Select the added ring of data, and choose Change Series Chart Type from the pop-up menu. Choose one of the XY types. Here I’ve selected the line and markers option (below left); if you were plotting the advance of alien spacecraft you’d probably want the markers only option.

Excel has plotted the XY data on secondary axes: the axis labels of both are plainly visible in the left chart below. Format each secondary axis scale in turn so the minimum and maximum are equal but with opposite signs; in this case min is -10 and max is +10. Format the axis so there are no tick marks and no tick labels, and use the same line style as the donut grid borders, 0.75 points thick and 25% gray (below right).

Excel Polar Plot Steps 5 and 6

Remove the major vertical and horizontal gridlines (below left). Remove the unwanted legend entries; click once to select the legend, then once more to select the unwanted entry, then click Delete (below right). If there is only one series of XY points, you can probably dispense with the legend.

Excel Polar Plot Steps 7 and 8

Expand the size of the plot area (below left), and format the series lines and markers if desired (bottom right).

Excel Polar Plot Steps 9 and 10

This may be complete enough for you, but as always, there are embellishments available to the clever chartmonger.

Modified Grid

You can change the grid if you like. If I use the following expanded data, the inner few donuts have only 4 arcs, each covering 90° of the ring. The next few have 12 arcs, as above, each covering 30°. The last few have 24 arcs, covering 15° each.

Excel Polar Plot Extended Grid Data

The resulting grid is shown without data below left, and with data below right.

Excel Polar Plot Fancy Grid

You can show the central circle (donut hole) without the crosshairs if you format the secondary axes to use no line color instead of 25% gray.

Excel Polar Plot Fancy Grid Without Crosshairs

Compass Point Labels

Suppose this is an actual geographic representation and you want to label the points of the compass. Set up data as shown below left. Copy the green range, select the chart, and use Paste Special as above. This series is plotted using the same chart type as the previous paste series was converted to, XY scatter with lines and markers.

Excel Polar Plot with Labels Data and Step 1

Add labels to the new series; the default Y values are used in the labels (below left). Remove the title and legend, or shrink the plot area to make room for the labels.

Change the label positions to Above (for the north label), Right (east), Below (south), and Left (west).

Excel Polar Plot Steps 2 and 3

Change the labels as appropriate (below left). You can use one of these approaches:

  • Select each label (click to select the series of labels, then click again to select the individual label), double click to edit the label’s text, and type the label you want.
  • Select each label (click to select the series of labels, then click again to select the individual label), type an equals sign in the formula bar, and click on the cell containing the label you want. The formula bar will show the link, e.g., =WorksheetName!$F$2.
  • Download and install Rob Bovey’s free Chart Labeler from http://appspro.com. This allows you to assign labels from a worksheet range to the points in a chart.
  • If you’re using Excel 2013, you can format the labels to use Values from Cells, and select the range of cells containing your labels.

Finally, format the last data series so it uses no lines and no markers (below right).

Excel Polar Plot Steps 4 and 5

Peltier Tech Chart Utility

Peltier Tech Chart Utility

 

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