Peltier Technical Services, Inc.
 

Peltier Technical Services, Inc.
- Custom Excel Solutions

PTS Blog: Charts and Things

Jon's Excel and Charting Pages
- Jon's Charts - Tutorials - Excel
- Site Index and Search - RSS


PTS Utilities

Commercial Utilities developed by Peltier Technical Services

  Waterfall Chart
  Box and Whisker
 

Excel Books

Books that I own and use while developing in Excel

Goods and Services

Excel or charting related products and services which I use or feel are worthwhile additions

 

Arbitrary Gridlines and Axis Labels

Here is another example of Arbitrary Axis Labels and Arbitrary Gridlines, together in the same chart. I received the following data (columns A and B) and the related chart with a request for special formatting.

  A B C
1   Data Category
2 2002 34.46 1
3   36.90 2
4   36.43 3
5   38.12 4
6   38.67 5
7   40.52 6
8 2003 41.10 7
9   42.24 8
10   43.29 9
11   43.43 10
12   44.44 11
13   45.10 12
14 2004 46.03 13
15   48.45 14
16   48.51 15
17   49.89 16
18   51.80 17
19   51.30 18
20 2005 53.22 19
21   53.73 20
22   55.72 21
23   56.26 22
24   56.86 23
25   58.78 24
26 2006 59.38 25
27     26
28     27
29     28
30     29
31     30
 


Original Line Chart with Indistinct Gridlines and Off-Center Axis Labels

The original line chart has six categories per year, with the year label in the first category of the year, which means that the year label is not centered under the whole year. Also the six gridlines were stuck with the same formatting, and a more distinct line was needed between years. (Note that the data range extended a few blank rows below the existing data, to chart an integral number of years.)

To help with the explanation, I've added the category number of each point in column C at left. On the category axis in a line chart (or in a column or area chart), Excel treats each categories as a list of items, with implicit values of 1, 2, 3, etc. As far as Excel is concerned, the chart is like the one below.


Excel treats categories as whole numbers 1, 2, 3, etc.

We will use a helper series with points along the X axis to serve as anchors for the error bars we will add for our gridlines, and another series, also along the X axis, to serve as anchors for the data labels we will use for our desired axis labels. Although a line chart treats line chart series as only having whole number X values, we can add a series and convert it to an XY type series, and Excel will treat its X values as numerical values. Therefore, we will add our helper series and change them to XY series.

The first data point in the main chart series is at 1, and we want a distinct gridline half a unit before it, at 0.5. After this we want gridlines every six units along the X axis, at 6.5, 12.5, etc. We will place a point at each of these X values along the Y axis (Y equals zero). The data for the Gridlines helper series is shown in E1:F7 below.

We want year labels in the middle of each year's data, between the third and fourth categories. We will use 3.5 for the first category label, and add 6 for the location of each additional label, so they will lie at 3.5, 9.5, 15.5, etc. We will place a point at each of these X values along the Y axis (Y equals zero). The data for the Labels helper series is shown in H1:J6 below.

  E F
1 GridlinesX Gridlines
2 0.5 0
3 6.5 0
4 12.5 0
5 18.5 0
6 24.5 0
7 30.5 0
 
  H I J
1 LabelsX Labels Label Text
2 3.5 0 2002
3 9.5 0 2003
4 15.5 0 2004
5 21.5 0 2005
6 27.5 0 2006

Add the Gridline data to the chart. Copy the Gridline data in E1:F7, select the chart, and use Paste Special from the Edit menu to add the data to the chart as a new series, with series in columns, categories in the first column, and series names in the first row.


Gridlines series added, but not visible

Now select the added Gridline series so it can be changed to an XY type. The series is not apparent in the chart (except for the legend), so use the dropdown chart element selector in the Chart toolbar, and select the Gridline series.


Chart Element Selector Dropdown on the Chart Toolbar

With the series selected, choose Chart Type from the Chart menu, and select the XY chart subtype with markers and no lines. The markers now appear on the X axis, but not at the exact positions we expected, because Excel has helpfully added secondary axes to the chart.


XY series located by default on Secondary axes

Like many helpful things Excel does, we have to partially undo it. We will keep the secondary Y axis, so our error bars can remain a constant height even if changes to the main series data causes causes to rescale the axes. We will scrap the secondary X axis, and Excel will use the primary X axis for all series in the chart. Select Chart Options from the Chart menu, click on the Axes tab, and uncheck the box next to Secondary Value (X) Axis.


Line and XY series share a common X category/value axis

The secondary Y axis is important to the chart, but not to the viewer. First, set its axis limits so Excel doesn't automatically autoscale it. Double click on the axis, and on the Scale tab, enter 0 and 1 for Minimum and Maximum, and make sure the Auto boxes in front of these values are unchecked. Hide the axis by double clicking on it, click on the Patterns tab of the Format Axis dialog that pops up, and select None for all options.


Hidden secondary Y axis makes chart look "normal"

Add the Labels data to the chart. Copy the Labels data in H1:I6, select the chart, and use Paste Special from the Edit menu to add the data to the chart as a new series, with series in columns, categories in the first column, and series names in the first row. Excel remembers that we changed the previous added series to an XY type, so it adds this one automatically as an XY type, not a Line type. This is a helpful thing that we don't have to undo!


Labels series added to the chart

Add custom gridlines by adding error bars to the Gridlines series. Double click on the Gridlines series, click on the Y Error Bars tab, click the Plus icon under Display, and set the Error Amount to a Fixed Value of 1 (the maximum value we locked into the secondary axis). The error bars are shown below in red.


Error bars added as custom gridlines

The way to get the custom X axis tick labels is to apply data labels to each point in the Labels helper series, then change the label to display the desired text. This becomes tedious after about two labels. To do this easily, you need Rob Bovey's Chart Labeler, a free and absolutely must-have add-in available from Application Professionals. It's compatible with every version of Excel since 97, and is easy to install and use. It is started through an added command, XY Chart Labels, on Excel's Tools menu. Use the Labeler to add the labels in J2:J6 to the Labels series, aligned below the points. The added labels are shown below in green.


Chart Labeler Dialog


Data labels added as custom axis labels

A little more cleanup is needed. Hide the markers for the two helper series: double click on each in turn, and on the Patterns tab, choose None for Markers. Hide the default X axis labels: double click on the axis, and on the Patterns tab, choose None for Tick Mark Labels. This causes the plot area to stretch downward: select the plot area, and drag its lower edge upward until there is sufficient room for the added labels. There is only one relevant series in the chart, so the legend is redundant: select the legend and press the Delete key. If there were two or more meaningful series in the chart, the legend entries for the helper series can be hidden. Single click on the legend, then single click on the text of an extraneious legend entry, and press the Delete key. Don't click on the legend key, the marker in front of the legend entry text, because deleting a legend key removes its series from the chart.


The finished chart

 

 

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


Peltier Technical Services, Inc.
We can customize or automate any example from this site, or build a new one for you. To discuss your project or obtain a quote, please contact me at jonxlmvp@peltiertech.com

PTS Blog: Charts and Things

Jon's Excel and Charting Pages
- Jon's Charts - Tutorials - Excel - Site Index and Search - RSS

Peltier Technical Services, Inc., Copyright © 2008. All rights reserved.
You may link to this article or portions of it on your site, but copying is prohibited without permission of Peltier Technical Services.

Microsoft Most Valuable Professional

Microsoft Most Valuable Professional

My MVP Profile