Peltier Tech Blog

Excel Chart Add-Ins | Training | Charts and Tutorials | Peltier Tech Blog

 

Main menu:

Peltier Tech Chart Utilities for Excel Peltier Tech Panel Chart Utility Peltier Tech Waterfall Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

 
Excel Dashboards
 

 
Amazon Books
 

Subscribe

Site search

Subscribe

Site search


Recent Posts

Popular Posts

Privacy and License

Privacy Policy

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

Chart with a Dual Category Axis

 
by Jon Peltier
Tuesday, April 22nd, 2008
Peltier Technical Services, Inc., Copyright © 2012.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Through appropriate arrangement of your source data, you can give your chart a dual category axis. This approach works with chart types that have an “Category” type category (X) axis, that is. line charts, column charts, and bar charts. The chart below shows defect rates in several different components, which are grouped into a smaller number of categories.

Column Chart with Dual Category Axis

The data arrangement is shown in the following table:

 

A B C D E
1 Mechanical Electrical Hydraulic
2 Mechanical Gear 11
3 Bearing 8
4 Motor 3
5 Electrical Switch 19
6 Plug 12
7 Cord 11
8 Fuse 3
9 Bulb 2
10 Hydraulic Pump 4
11 Leak 3
12 Seals 1

 

There are three categories: Mechanical, Electrical, and Hydraulic. These categories are listed in the first column, and also in the first row. The second column shows the sub-categories, for example, Gear, Bearing, and Motor under Mechanical. The cells filled with yellow should be completely blank. The first two cells in the top row are blank to instruct Excel to use the first row as series names and the first two columns as category labels. The blank cells under each main category in the first column tells Excel that each main category applies to several subcategories. I used separate columns for the three categories so that each is plotted in its own series, making it easier to format each major category separately.

 

To make the chart, select this entire data range and insert a stacked column, stacked bar, or unstacked line chart. (Note: you could use clustered column or bar charts, but then you would have to format each to use an overlap of 100% between series.)

Line Chart with Dual Category Axis

The column chart type is probably the best selection (see top of page), as long as there are not too many categories and subcategories. The line chart (above) gives more emphasis to an illusory relationship between points by connecting them with lines. The bar chart (below) works almost as well as the column chart, but Excel provides no way to orient the major categories horizontally.

Bar Chart with Dual Category Axis

First in a series

Related Posts:

Learn how to create Excel dashboards.

Comments


Comment from Tony
Time: Tuesday, April 22, 2008, 4:16 pm

I agree that the top chart is the best layout for this data. The line chart leads me to think that time is on the x-axis or there is a relationship between the series, which is not accurate. Also, nice use of color!

One point; the y-axis scale is different in the bar chart (5) versus column chart (2). I am leaning towards the preference of the y-axis scale being two.

Would you suggest a pareto chart for this data?

Nice tip!


Comment from Jon Peltier
Time: Tuesday, April 22, 2008, 5:11 pm

Tony – I included the line and horizontal bar versions of the chart almost as an afterthought, so I didn’t notice the change in the Y axis scale of the bar chart. I agree that it looks better, more precise maybe, using an axis tick spacing of 2, so I made the change and uploaded the new chart.

If you notice, this is almost a pareto chart, at least within each category the data is sorted from high to low. You could set up an Excel pivot table (I feel my next post coming on) that would sort both outer and inner categories by number of occurrences.


Comment from Robert Martim
Time: Saturday, May 10, 2008, 1:20 pm

Hi Jon,

“Funtastic” chart! It is a pitty I am color-blind and cannot appreciate the “nice use of color” that Tony mentions above. Nevertheless, the result is very clean and very easy to read.

The column chart gives a perfect picture of the data in a clea, clean and concise way!

Thanks for sharing this!

Rob


Comment from Mick Coleman
Time: Friday, June 12, 2009, 6:45 am

Jon,

is there any way of separately formating the x-axis ?
E.g. different font colours for Mechanical or Engineering (especially if you wanted to minimise the number of formating lines in the graph) ?


Comment from Jon Peltier
Time: Friday, June 12, 2009, 6:59 am

Excel doesn’t allow for individually formatted axis tick labels. You can fake it using dummy series, as shown in Individually Formatted Category Axis Labels. For a dual set of labels it requires two dummy series and some cleverly laid out text labels.


Comment from Shirlene
Time: Friday, June 12, 2009, 11:10 am

I have been fighting a problem with this category layout in Excel 2007. Jon, I know you are not happy with 2007 but I wonder if you know of a work-around. When doing the multi-level, or dual, category X-axis, it works great in XL2003. It also works great in XL2007…up to 100 rows of data. As soon as the 101st row of data is added, the group category (your Electrical, Mechanical, Hydraulic above) removes every other group.

Do you have any ideas on how to fix this?

Thanks,
Shirlene


Comment from Jon Peltier
Time: Friday, June 12, 2009, 3:18 pm

Shirlene -

This is what they call a “known issue” in Excel 2007. I have not tried to find a workaround for this, since in general more than 100 categories make an axis unreadable. I think the 100 category limit plays havoc with single lavel axis labels too.


Comment from Shirlene
Time: Tuesday, June 16, 2009, 5:56 am

Thanks for the reply. That’s what I suspected but thought that you might have found a work-around for it. I’ve tried and haven’t been successful. My user’s chart contains all 50 states as the outside level and 5 categories per state on the second level. This chart is not printed and this is what her boss wants so she is stuck doing it this way.

If you do find or hear of a work-around, please let me know. I’d really appreciate it and so would my user.

Thanks,
Shirlene


Comment from Jon Peltier
Time: Tuesday, June 16, 2009, 8:36 am

So there are 250 categories? I can’t think of a good way to do that!


Comment from Shirlene
Time: Tuesday, June 16, 2009, 9:40 am

I agree but this is what the user wants. And, sadly enough, it worked fine in XL2003.

Thanks for your help, anyway, Jon. I appreciate your comments.

Shirlene


Comment from Jon Peltier
Time: Tuesday, June 16, 2009, 3:55 pm

Shirlene -

It just occurred to me that Excel 2007 has a problem if there are more than (I think) 99 category labels. Above this number, you no longer have any control over how the labels are displayed.

You might try to use a alternate approach, Individually Formatted Dual Category Labels, which uses data label on invisible series instead of the built-in axis labels. Excel will put all of the labels wherever they go, no matter whether they overlap. So it will get around Excel 2007′s problems with too many category labels.


Comment from Jon Peltier
Time: Thursday, September 24, 2009, 11:26 am

Hi Simon -

If you don’t want different formatting for the different main categories (Mechanical etc.), then move the ‘this year’ data from columns E and G into column C, and the ‘last year’ data from F and H into D, and only use columns C and D for your Y values.

Also thanks for the printer friendly suggestion. I have certainly considered this option, but haven’t gotten around to figuring out how to implement it. One of these days.


Comment from Simon
Time: Thursday, September 24, 2009, 10:28 am

Hi Jon,
Thanks again for your blog, I keep coming back to it to learn how to do stuff I want to do, or just to get new idea.

Before my main question, here’s a suggestion : Would it be possible to make a “printer friendly ersion” of the page? I like to print some of your pages because I dont have internet on my work computer and I dont need the menus on the left and other stuff.. Thanks :)

Main question:
I am trying to make a dual-axis very similar to yours, but I want to display two numbers for each category. For example, Mechanical-Bearing would have ‘failure rate last year’ and ‘failure rate today’. The problem I have is if I want to display the legend, it shows these 2 variables as many times as I have categories.

any idea?
Thanks
Simon


Comment from Stuart West
Time: Thursday, October 8, 2009, 10:51 am

Hi Jon,

I’m having a problem with a chart like the one at the top of the page. For chart formatting reasons, the top and bottom cells in each subcategory group have been left empty (so in your example, B2 would be empty, Gear, Bearing and Motor would be in B3 to B5, B6 would be empty and so on). This works great except for the last empty cell in the table, which Excel treats as a new category instead of a subcategory. Can you suggest any way around this?


Comment from Jon Peltier
Time: Thursday, October 8, 2009, 12:35 pm

Stuart -

Where is the last empty cell in my table (corresponding to yours)? Do you mean A12? Make sure the cell is really empty, and doesn’t contain for example a stray space character.


Comment from Stuart West
Time: Friday, October 9, 2009, 4:39 am

Hi Jon,

Thanks for the response. It’s probably easiest if I show an example.

The last row of the table contains only blank cells, but always shows up on the chart as a new category.


Comment from Jon Peltier
Time: Friday, October 9, 2009, 7:18 am

Stuart -

I see. In both Excel 2003 SP3 and 2007 SP2, if row 31 is completely blank, or if cell B31 contains a space character, the last item is a subcategory. If A31 contains a space character or a formula that returns “”, Excel recognizes it as a non blank cell in column A and gives it its own category. Select cell A31 and press Delete, and it should fix the axis labels.


Comment from Stuart West
Time: Friday, October 9, 2009, 7:50 am

Thanks! Somehow pressing delete wasn’t helping, but putting a space character in B31 sorted out the problem. That had completely stumped everyone in the office, so thanks again.


Comment from Tyler
Time: Tuesday, January 12, 2010, 4:02 pm

Hi Jon,

Thanks for this great site, it’s very helpful!

My question is this: I use multi-category charts in Excel 2007 on a regular basis. In many of mine, I have a large number of categories and each has only two sub-categories. In some cases the category names are long and the sub-categories are not, and I run into an issue where the category names do not wrap, resulting in overlapping letters with the next category. What puzzles me is that some of my charts DO wrap properly. I can’t find any setting for this. Do you know how I can cause my category names to wrap?

Thanks in advance,
-Tyler


Comment from Tyler
Time: Tuesday, January 12, 2010, 5:02 pm

Jon,

After more tinkering, I found that Excel wraps the categories if it has fewer than 14 of them in a single chart. If I add a 14th or beyond, the categories stop wrapping. Not sure if this is by design or a bug, but in any case I decided the simplest solution is to create a second chart and divide the categories across the two. This works for my purposes. Still a puzzling case though.

-Tyler


Comment from Tim Sorrell
Time: Wednesday, October 5, 2011, 5:24 pm

Jon… Using Excel 2007 and “mysteriously” my horizontal axis labels began wrapping character by character and now come out vertical. If I “stretch” the chart way out to the right, the labels begin to wrap more and more correctly. These charts were all working fine (wrapping correctly) two months ago when I last used them. Now all my charts are behaving in this strange fashion. It’s as if excel thinks there is some sort of “border” around each horizontal axis label, and when the labels get somewhat close to each other, it begins to wrap… and in my case, they wrap character by character. I have produced a .PDF file of the strange output. Could you take a look at the output and tell me if this is known bug that has been recently introduced into excel 2007? If can take a peek, How do I send the .PDF to you. Thanks very much for your help. My email is timsorrell@comcast.net.


Comment from Jon Peltier
Time: Thursday, October 6, 2011, 6:36 am

Tim -

I don’t know of a specific issue caused by a recent update to Excel 2007, but I’ve heard of several inconvenient problems. I have no suggestions. Labels (in fact, charts in general) are not handled well in Excel 2007. I avoid 2007 as much as possible, using 2003 for my own important work and 2010 for most of my outward-facing work.


Comment from frank
Time: Sunday, October 23, 2011, 10:40 am

finally solved my problem, searched the net for it (>12 hrs) , was told by friend that Jon Peltier is th best in excel take a look at his site, and finally found how to do this multi level category labels (or dual category axis)
needed that very much….
THANKS!!!


Comment from John Passmore
Time: Monday, March 19, 2012, 11:48 am

Jon

Have been trying to create your Defects chart in Access 2003 using VBA from a similar table as a prototype for something else I want to do later.

Not sure how Access interprets the various spaces you describe to let Excel know that there are to be Categories and sub-Categories. The trick is obviously to create the correct strings in the .SetData chDimCategories and chDimValues for each series so that they will be correctly interpreted as Cats and subCats.

Wonder if you could kindly provide me with any pointers please?


Comment from Jon Peltier
Time: Wednesday, March 28, 2012, 9:05 pm

John -

I don’t know about charting in Access. But in Excel, you can’t pass an array as a delimited string and have the dual axis come out right. You need to use a worksheet range.


Comment from John passmore
Time: Wednesday, April 18, 2012, 4:43 am

Many thanks for responding Jon,

Have now had a fair bit of success in rendering different types of charts in Access subforms from data in tables using vba to address OWC (10 and 11) chartspace objects, methods and properties. Basically have to get approriate sets of tab-separated strings of category names and values from the tables to pass to the .Set Data chDimCategories and chDimValues for each Series added.

Regarding your Defects chart, I haven’t been able to discover the correct way to pass info to chDimCategories about my requirements for true Categories and subCategories. I had to simulate your mix of cats/subs with a list of of names where the subcats were simply at the same level as the cats but offset (right-just) to appear as a hierarchy – a bit of a fudge!

I want to progress to a chart similar to the Defects chart where cats might be months and the subcats, a repeated set of names – such as income, expenses and balance, for one or more accounts.

Wonder if you can kindly provide a lead on what the sequence of names should look like in the string of cats passed into .SetData chDimCategories such that OWC will recognise a hierarchy of cats, sub-cats (and even sub-sub-cats?) – have noticed somewhere that there maybe some limit on the numbers of repeated names allowed.

Many thanks – John


Comment from Jon Peltier
Time: Wednesday, April 18, 2012, 7:24 am

John -

As I stated in my previous comment, it is not possible to pass anything other than a worksheet range that will produce a category axis with categories and subcategories. You cannot pass a string that will do this, nor can you pass a 2D array. At least I haven’t been clever enough to find a way.

I’ve only dabbled with OWC, but my suspicion is that they also will not accept a string or array to produce a multi-level category axis.


Comment from Henry
Time: Tuesday, April 24, 2012, 1:42 am

hi Jon,

Thanks for the great site. I have a situation where I wish to plot with more than just 2 categories of label… say

Tier 1 = Mechanical, Electrical, and Hydraulic
Tier 2 = as per your charts
Tier 3 = Country

Is this possible to do using fairly standard excel charts, or the only way is to adopt your “Individually Formatted Dual Category Labels” method? (The latter doesn’t give me the divider lines in the label).

Many thanks
Henry


Comment from Jon Peltier
Time: Tuesday, April 24, 2012, 6:56 am

Henry -

You can have more than two tiers. In my example, I have two columns of labels. For three tiers, you would use three columns of labels, arranged using the same logic.


Comment from Henry
Time: Wednesday, April 25, 2012, 7:11 pm

Hi Jon,

Thanks for your reply. I tried with that, but it didn’t work at first, so I thought I was doing something wrong, but now it’s all fine. Thanks heaps for your help.

Regards
Henry

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.





Subscribe without commenting

Peltier Tech Chart Utilities for Excel Peltier Tech Waterfall Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Panel Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

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