Peltier Tech Blog

Excel Chart Add-Ins | Training | Custom Solutions | Charts and Tutorials | PTS Blog

 

Main menu:

 
Peltier Tech
Chart Add-Ins

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

Subscribe

Site search

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Privacy Policy

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

Order of Legend Entries in Excel Charts

by Jon Peltier
Friday, February 13th, 2009
Peltier Technical Services, Inc., Copyright © 2010.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

One of the mysteries of modern life is the order in which series appear in the legend of an Excel chart. People have been driven mad while attempting to reorganize legends in their charts. I’ve spent years working with Excel charts, and I’ve made some observations and generalizations about Excel chart legends. These are only valid for charts in Excel 2003 and earlier, as there seem to be some substantial differences in behavior introduced by Excel 2007.

Summary of Legend Entry Order Rules

Before presenting the rules for legend entry order, a couple of terms need to be defined:

Axis Group – An axis group is the collection of all series plotted on an axis. There is always a primary axis group in a chart, and sometimes a secondary axis group.

Chart Group – A chart group is the collection of all series of a given type within an axis group. For example, there may be a primary line type chart group, or a secondary column type chart group.

When you manually reorder series in a chart, the series available for you to reorder at any given time are all part of a single chart group. You won’t even see other series in the list.

Here are the rules for legend entry order, in vertically listed legends, for charts with horizontal category (X) axes and vertical (Y) axes. The rules are explained and illustrated in the article below.

  • Series are listed according to chart type, in this order: Area, Column and Bar, Line, and XY.
  • Within each chart type, primary axis series are listed first, followed by secondary axis series.
  • Series within each chart group are listed according to plot order.
  • If the first chart group listed represents stacked series, series within all chart groups are listed in reverse order.

Effect of Series Type on Order of Legend Entries

Series are listed according to chart type, regardless of their plot order. The order of chart types in the legend is area, then column or bar, then line, and finally XY. This matches the bottom-to-top stacking order of the series in the chart.

Here are two combination charts with the same chart types. The area series is listed first and the line series is listed last, regardless of the plot orders of the series (the number at the beginning of the legend entry label).

Legend Order in Combination Chart with Areas, Columns, and LinesLegend Order in Combination Chart with Areas, Columns, and Lines

Effect of Axis on Order of Legend Entries

Series on the primary axis are listed before series on the secondary axis.

In the left hand chart below, the first two series are on the primary axis and the last two are on the secondary axis. In the right hand chart, this is reversed. In both cases, the primary axis series are listed first in the legend.

Legend Order in Chart with Primary and Secondary AxesLegend Order in Combination Chart with Primary and Secondary Axes

This relationship is true as long as all series are of the same chart type (e.g., all are area, column, or line chart series).

Effect of Series Type and Axis on Order of Legend Entries

If the combination chart has series on both primary and secondary axes, the plot order is dictated first by chart type, then within each chart type by axis. A combination of series that share chart type and axis is called a chart group.

The area chart series in the charts below are listed first, whether they are plotted on the primary or secondary axis.

Legend Order in Combination Chart with Primary Areas and Secondary ColumnsLegend Order in Combination Chart with Secondary Areas and Primary Columns

Order of Legend Entries in Stacked Charts

Generally series are listed in the legend in the order they are plotted. However, in vertically stacked charts (line, column, and area), if the legend lists the series vertically, the entries are reversed so they match the stacking order: series one on the botton, series two above series one, etc. In the following examples, the series are plotted in the order one, two, and three.

Here are unstacked and stacked line charts, with normal and reverse legend entry order.

Legend Order in Line ChartLegend Order in Stacked Line Chart

Here are unstacked and stacked column charts.

Legend Order in Column ChartLegend Order in Stacked Column Chart

Here are unstacked and stacked area charts.

Legend Order in Area ChartLegend Order in Stacked Area Chart

In a bar chart, whether clustered or stacked, entries in a vertically aligned legend are listed in the same order as they appear in the chart. The alignment matches the order of the bars in the chart, even if the order of the bars is reversed by plotting an axis in the reverse order.

Effect of Stacking, Axis, and Chart Type on Legend Entry Order

The order of all series within a chart group is reversed if the first chart group listed in the legend is stacked.

In the case where all series types are the same on primary and secondary axes, what matters is the stacking of the primary axis series. Unstacked primary series 1 and 2 in the chart at left are listed first, so no series are listed in reverse order, even though secondary series 3 and 4 are stacked. Primary stacked series 3 and 4 are listed first in the chart at right, so primary axis series 3 and 4 are reversed, as are secondary axis series 1 and 2, even though secondary series 1 and 2 are not stacked.

Legend Order in Chart with Primary and Secondary AxesLegend Order in Combination Chart with Primary and Secondary Axes

In the case where there are different chart types on primary and secondary axes, the behavior is dictated by the first chart group listed in the legend. In the chart at left, the secondary area series are stacked, so all chart groups (both the secondary area and primary column series) are listed in reverse order, regardless of whether the columns are stacked. In the chart at right, the secondary area series are unstacked, so no chart groups (neither secondary area nor primary column series) are listed in reverse order, even if the primary columns are stacked.

Legend Order in Combination Chart with Secondary Stacked Areas and Primary ColumnsLegend Order in Combination Chart with Secondary Areas and Primary Stacked Columns

Unique Horizontal Bar Chart Legend Entry Ordering

Here are a clustered bar chart and a stacked bar chart, with series listed in the order they appear.

Legend Order in Bar ChartLegend Order in Stacked Bar Chart

Here are a clustered bar chart with the category axis plotted in reverse order, and a stacked bar chart with thevalue axis plotted in reverse order. Again, the series are listed in the order that they appear in the chart.

Legend Order in Bar Chart with Reversed Category AxisLegend Order in Stacked Bar Chart with Reversed Value Axis

This reordering of a legend based on a reversal of the order of an axis only appears in a bar chart with a vertically aligned legend.

Related Posts:

Bookmark and share this entry:
  • Twitter
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Google Bookmarks
  • Reddit
  • MySpace
  • Slashdot
  • Yahoo! Buzz
  • Tumblr

Learn how to create Excel dashboards.

Comments


Comment from Gordon
Time: Friday, February 13, 2009, 8:33 am

Brilliantly explained as usual Jon, thanks. Makes (almost) perfect sense now you’ve explained the ground rules, why can’t Microsoft document their own products to this degree?.


Comment from Andy Pope
Time: Friday, February 13, 2009, 8:44 am

Hi Jon,

Are going to cover Trend lines in another article?

About 4 years ago I tried to create a addin that would allow users to select which items would appear or be hidden in the legend. But I gave up in the end as the combinations you have describe were just too convoluted to code and get reliable results.


Comment from Jon Peltier
Time: Friday, February 13, 2009, 10:32 am

Yeah, trendlines mess up the legend, and I forgot about that. I think they (and error bars) also mess up the series indexes and the series sequence, but I don’t recall exactly how.

I’d like to see a simple property added to the Series object: AppearsInLegend. Even better, how about making the LegendEntry object a member of the Series class, then adding .Visible to the LegendEntry. Unfortunately for 2007, they removed more than they added to Excel charting. I do not have high hopes for improvements in Excel 14.


Comment from Andy Pope
Time: Saturday, February 14, 2009, 5:49 am

Either of those suggestions Jon would be a useful addition to the OM.


Comment from Jan Schultink
Time: Saturday, February 14, 2009, 2:34 pm

Great research and explaining.

The order in which the automated Microsoft legend appears is one of the reason I usually create them manually in PowerPoint charts. A bit more work but 100% in my control.


Comment from Indigo
Time: Wednesday, July 8, 2009, 4:02 pm

What should I do with a combination chart (column and line) that does not seem to follow your rules? I have 6 legend entries, 3 are column and 3 are line. I cannot seem to sort the legend so that it comes up as:

— North Plan [ ] North Actual
- – South Plan [ ] South Actual
->- West Plan [ ] West Actual

No amount of fiddling I do with the series order will get it to line up nicely. All I get is:

— North Plan [ ] North Actual
- – South Plan [ ] South Actual
[ ] West Actual ->- West Plan


Comment from Jon Peltier
Time: Wednesday, July 8, 2009, 4:50 pm

Indigo -

When I make a chart such as you describe, I get three column series in the legend followed by three line series. When I set up the legend to show three rows and two columns of entries, the top two and the first in the middle row are column series. There’s no way to get the lines in one column of legend entries and the columns in the other. You could make a two-row legend, with all the column series in one row.


Comment from John Krumm
Time: Wednesday, October 7, 2009, 8:16 pm

Thanks for this informative post. It really helped me get a chart looking the way I wanted it to. My problem was that I wanted to show only a subset of the legend, so I need the ones I wanted to show near the top of the legend. I couldn’t do this because I had a secondary vertical axis, and one of the legends that I wanted near the top was on this axis. I ended up creating a small phantom series on the primary vertical axis with the legend entry that I wanted to show. This phantom series was tiny, in my case a really short line segment, but I gave it the right series name and line type to give the legend entry I wanted.. Now its entry is near the top of the legend like I want, but you can’t see the actual series on the chart. Problem solved.


Comment from Jon Peltier
Time: Wednesday, October 7, 2009, 8:37 pm

John -

Good job. Just because it doesn’t seem like Excel can do something, doesn’t mean you should stop trying to think of other ways to do it. I like your phrase “phantom series” better than the “dummy series” I’ve been using all along. I might have to adopt it as my own.

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 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

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