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.

Fill Below an XY Chart Series (XY-Area Combo Chart)

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

How can you fill the area below an XY series in an Excel chart? You can’t just use an area chart for this, because the X axis won’t work out right, and an Area chart does not provide markers, only border and fill.

Fill the area below and XY chart series

The trick is to use a chart that combines XY and Area type series. I described this technique in XY Area Chart: Fill Below an XY Series, but that protocol doesn’t work the same in Excel 2007 as in earlier versions. Fortunately by rearranging some of the steps, a process can be designed that works for all versions of Excel, from 97 (maybe earlier) through 2007. This tutorial explains the redesigned protocol.

Here is the data for this example. The XY data is in columns A and B, and the area chart data in C and D. The X values of the area chart series will be plotted on a date scale which ranges from 0 to 1000 (1000 should provide plenty of resolution for a small chart). The minimum and maximum in column C are thus 0 and 1000. The other X values are scaled to the X values of the XY series, which will be scaled between 0 and 15.

The scaling formula in C4 is

=INT(1000*A4/15+0.5)

or in the general case

=INT(1000*(A4-Xmin)/(Xmax-Xmin)+0.5)

This formula is filled down to cell C11.

Cell C3 contains the formula =C4, and cell C12 contains the formula =C11.

The values in column D are linked to the corresponding values in column B, except for the zeros at the ends of the range. The duplicate X values produce a vertical edge in the area chart, when plotted on a date scale axis. The zeros at X=0 and X=1000 automatically scale the area chart axis, which is an improvement on the older technique.

XY-Area Combo Chart Data

The protocol starts by selecting the XY data range A3:B11 and creating an area chart (not an XY chart as in the old protocol, since that gets messed up in Excel 2007). The Excel 2003 chart is shown at the left, the Excel 2007 chart at the right.

XY-Area Combo Chart, Excel 2003 Step 1 XY-Area Combo Chart, Excel 2007 Step 1

Continue by copying the area data in C1:D13, selecting the chart, and using Paste Special to add the copied data as a new series with categories in the first column and series names in the first row.

XY-Area Combo Chart, Excel 2003 Step 2 XY-Area Combo Chart, Excel 2007 Step 2

The area series is moved to the secondary axis. In 2003 (left), double click on the series, and on the Axis tab, choose Secondary. In 2007 (right), right click on the series, choose Format Data Series, and on the Series Options tab, choose Secondary.

XY-Area Combo Chart, Excel 2003 Step 3 XY-Area Combo Chart, Excel 2007 Step 3

The first series is then converted to an XY type. Right click on the series, choose Chart Type, and select the XY type and subtype you want.

XY-Area Combo Chart, Excel 2003 Step 4 XY-Area Combo Chart, Excel 2007 Step 4

Excel only adds a secondary Y axis, and we need a secondary X axis, with a date scale. In Excel 2003 (left), go to Chart menu > Chart Options > Axes tab, check the box in front of Secondary Category (X) Axis, and select the Time Scale option. Excel 2007 (right) requires two steps. First, on the Chart Tools > Layout tab, click the Axes dropdown arrow, then Secondary Horizontal Axis, and select Show Left to Right Axis. Then right click the new axis, choose Format Axis, and under Axis Type on the Axis Options tab, select Date Axis.

XY-Area Combo Chart, Excel 2003 Step 5 XY-Area Combo Chart, Excel 2007 Step 5A
XY-Area Combo Chart, Excel 2007 Step 5B

Now hide the secondary X axis and make sure the highlighting in under (not over) the XY series. In Excel 2003 (left), step 1 is to double click on the axis, and on the Patterns tab, choose none for major and minor tick marks, tick labels, and axis lines. Excel 2003 Step 2 is to double click on the secondary Y axis, and on the Scale tab, uncheck Category (X) Axis Crosses At Maximum. In Excel 2007 (right), right click the axis, choose Format Axis, and on the Axis Options tab, choose None for major and minor tick mark types and tick labels, and on the Line Color tab, choose No Line. In 2007, the fill is already under the XY series despite the position of the X axis.

XY-Area Combo Chart, Excel 2003 Step 6A XY-Area Combo Chart, Excel 2007 Step 6
XY-Area Combo Chart, Excel 2003 Step 6B

Finally, in either version of Excel, select the secondary Y axis (right edge of the chart), and press Delete.

XY-Area Combo Chart, Excel 2003 Step 7 XY-Area Combo Chart, Excel 2007 Step 7

My next post will show how to use a variation on this technique to fill between two XY series.

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 Jeff Weir
Time: Monday, September 28, 2009, 4:35 am

Hi Jon. Great tutorial…I fiddled around for hours at the beginning of the year trying to do this before I succeeded.

If you want a quick and dirty way to achieve nearly the same thing, you could also plot the original data as an area graph and then tell Excel that the x axis is a date axis. It then plots the data like a scatterplot, albeit it rounds down any points on the x axis to the nearest whole number. But hey…if you’re in a hurry, and your numbers are generally big enough so that you don’t need decimal precision on that axis, then it works a treat.

I’ve posted an example using your data , and I’ve overlayed it over your scatterplot to show the effect of the rounding of X axis data. As you can see, it’s not a great match, but maybe good enough for most purposes.

But wait…there’s more. If you do need decimal precision on that x axis (i.e. you want a perfect match), then here’s a crafty work around: Say your x series has two decimal points like in the example above. Multiply your x axis data by 1000 and plot it as an area chart. Because we multiplied by 1000, every point in that x series is now an integer, and so it doesn’t get rounded down as per the previous example above.

Now here’s the crafty bit…select that x axis, select ‘Date axis’ as the axis type and then make the major unit ‘fixed’ at 1000 days.

Then change the custom number formatting to ##0.

You’ll end up with a pretty good imitation of a scatterplot where once again I’ve overlayed it on top of the actual scatterplot. Perfect fit.

I’ve uploaded a spreadsheet with this example to http://cid-f380a394764ef31f.skydrive.live.com/self.aspx/.Public/Scatterplot%20vs%20area%20graph.xls


Comment from Jon Peltier
Time: Monday, September 28, 2009, 7:19 am

Jeff -

Often you can get away with faking the axis you want. If you want percentages you can multiply by 100, and use a format of 0″%” (the percent sign in quotes so it’s treated as a generic character), which is how I handled the X axis in the PTS Marimekko Chart Utility (oh no, the secret’s out). But there are times when it will not work: logarithmic axes for example, or values which are too large (dollar values in the billions or so, I don’t recall the exact limit).

I’ve found this to be a flexible way to get this shading with “good enough” precision. Especially if the chart is to be created programmatically, it’s too complex to have the code think “can I multiply by 1000?”, “can I multiply by 100 and fake percentages?”, etc.


Comment from Colin Banfield
Time: Monday, September 28, 2009, 12:32 pm

Jon, superb technique…as usual. In the above description, it appears that you’re missing the piece where you convert the area chart on the primary axis to an XY chart, followed by formatting the primary axis.

Jeff’s suggestion is not without merit. I’ve done a similar thing, but with a twist. For example, add the following two rows at the top of your data set (I’ve assumed that your first “real” data points (2, 37) start at A6 and B6):

0 =NA()
=A6 =NA()
2 37
3.27 31
6.26 19
7.58 42
8.33 14
9.79 41
11.2 29
13.86 25

Using the above data, create an area chart, followed by a line chart. Format the X axis as a date axis and set max, min & major unit as in your example.


Comment from Jon Peltier
Time: Monday, September 28, 2009, 1:19 pm

Colin -

That’s a strange omission. I noticed the sentence was missing (after already scheduling the post) from both this and the sister article which is coming out in a day or two. I typed the sentence into this post, copied it, typed it into the other post and edited it, and (I thought) saved both. Apparently I only saved the other post, but that means I was able to copy the sentence, paste it in here, and change it to fit. So now it’s fixed.

The problem with the Area/Line approach (left) is that the X values are all truncated to the next lower whole number value by the line and area series, while the XY series (big and red) considers fractional parts of its inputs (right):


Comment from Jeff Weir
Time: Monday, September 28, 2009, 3:15 pm

In hindsight, I see my workaround doesn’t address the point in your post that an Area chart does not provide markers…to do this, I’d need to add another series using the same y data , and then change series type to line with markers. (Example at http://screencast.com/t/jWQALUXAaoBT )

Also I see that your scaling formula does the same thing as in my suggestion of multiplying the X series by 1000…the only difference being that I handle the implications of this to the x axis by using a custom number format to rescale the axis, wheras you add another axis.

Many ways to skin a graph, I suppose…


Comment from Jon Peltier
Time: Monday, September 28, 2009, 3:32 pm

In 2003 and earlier, it was pretty easy to manipulate the XY component of a combo chart, but in 2007 it’s more entangled. A lot of my old tutorials fall down, becuase while 2003 allowed you to pursue several different paths to a final solution (it was path-independent), 2007 often will only work following one path.


Comment from Bill Gates
Time: Monday, September 28, 2009, 4:10 pm

The one TRUE path, Jon…


Comment from Colin Banfield
Time: Monday, September 28, 2009, 7:27 pm

“The problem with the Area/Line approach (left) is that the X values are all truncated to the next lower whole number value by the line and area series, while the XY series (big and red) considers fractional parts of its inputs (right):”

Yes, I expected that there would be a difference because the date axis only gives us full days (whole numbers). However, I didn’t realize how much of a difference there was between the two approaches until I did a close comparison. Because the numbers are small, the decimals takes on significance.

The moral of this exercise is that the area/line chart is OK in the limited case of whole numbers (or if the decimals aren’t significant or if you can round up the numbers…until such time as Excel gets a date axis that can handle fractions of a day). The XY/area is the way to go if decimal precision is important. It’s certainly a great solution.


Comment from Colin Banfield
Time: Tuesday, September 29, 2009, 7:21 am

“Also I see that your scaling formula does the same thing as in my suggestion of multiplying the X series by 1000…the only difference being that I handle the implications of this to the x axis by using a custom number format to rescale the axis, wheras you add another axis.”

I ended up doing this with my version of the Line/Area chart. Since the area chart in the XY/Area combo has to be scaled to the precision of the XY chart, it amounts to the same thing…with less work.


Comment from Jon Peltier
Time: Tuesday, September 29, 2009, 8:29 am

Jeff’s scaling trick is clever, and works in many cases where the axis values can be invisibly scaled by a thousand or a million. It also only works in Excel 2003 up to an X value of 2,958,465; after this the date-scale axis reverts to a category axis (though formatting the scale of the axis still brings up the date scaling dialog). I guess if the X values are this high, you could divide by 1000.


Comment from Colin Banfield
Time: Tuesday, September 29, 2009, 8:58 am

In creating the “scaling” range from the original dataset, you could use a formula to check the extremes of the dataset to determine how to scale (multiply or divide). I tend to agree with you that line and XY charts should be combined (after all, the date axis is a whole number numeric axis). It would certainly save a lot of hassle when making combo charts.


Comment from David Montgomery
Time: Wednesday, September 30, 2009, 10:48 pm

Hi Jon,

Great post! I got the chart to work just fine, but I ended up modifying it slightly. The data that I would plot on a chart like this tends to intersect quite a bit, so I wanted to use different colors for positive and negative area.

I’m sure there is an easier way to do this (maybe in the sister post you were referring to?), but I ended up calculating the points where the lines intersected using SLOPE() and INTERCEPT(). It gets a little ugly, but I put an explanation and the workbook up on my blog if anyone is interested:

Two Color XY -Area Combo Chart

The end result turned out pretty well, and I haven’t played with it too much but all of the formulas should be scalable.


Comment from Jon Peltier
Time: Thursday, October 1, 2009, 7:04 am

David – Nice article. Thanks for expanding on this technique.


Comment from David Montgomery
Time: Thursday, October 1, 2009, 11:19 am

Thanks Jon! I think I overshot the comment section I wanted though, I meant to respond to the post above this one.


Comment from haberler
Time: Sunday, March 14, 2010, 8:52 pm

I ended up doing this with my version of the Line/Area chart. Since the area chart in the XY/Area combo has to be scaled to the precision of the XY chart, it amounts to the same thing…with less work.


Comment from Richard Groff
Time: Friday, April 23, 2010, 11:41 am

Great site! In re-creating the exercise, when I displayed the secondary-x axis the area changed from under to over and didn’t return until I deleted the secondary-y. In your tutorial you write “Now hide the secondary X axis and make sure the highlighting in under (not over) the XY series.” Mine did and I can’t figure out how to fix it at this step. Does anyone know what causes it to flip over?


Comment from Jon Peltier
Time: Friday, April 23, 2010, 7:01 pm

Richard -

This fill goes between the X axis and the series. When Excel adds secondary axes to the chart, usually the secondary X axis is at the top of the chart, so the fill goes from the top of the chart to the series. You have to format the secondary Y axis to make the X axis cross at zero.


Comment from Richard Groff
Time: Saturday, April 24, 2010, 6:34 am

Thanks for the write back. I finally figured my issue out. It is necessary to choose a stacked area chart from the beginning to keep the secondary chart from flipping when you turn on the secondary x-axis. If you choose side-by-side (as I originally did), it will work, but the secondary series area won’t flip to “under” until you delete the secondary y-axis. In the end you get the same result, but I like your method better as it is a better process for the more complex charts.

Thanks again for an amazing site!!


Comment from Rebekah
Time: Thursday, April 29, 2010, 9:20 am

Hi Jeff,

Thanks for a great post. I was able to follow it easily and acheive the same results that you described and illustrated. However, when I try to apply the same protocol to my data, it doesn’t turn out the same. I am not sure, but I think that I may be having some difficulties with scaling for my data.

X Y
-1 283
-0.43 249
-0.29 271
0 260
0.57 105
0.86 108

My Xmax will be 6 and Xmin is -1.

So I changed the scaling equation for Column C to =INT(1000*(A4+1)/7+.5).

I am not sure what I am doing incorrectly, but the XY series and the Area series are not matching up at the end.

Will you let me know if you fiqure out why this isn’t working for my data?

Thank you!


Comment from Jon Peltier
Time: Thursday, April 29, 2010, 1:19 pm

Rebekah -

I worked through the example with your data:

Rebekah-XYArea.xls


Comment from Rebekah
Time: Friday, April 30, 2010, 11:24 am

Hi Jon,

Thank you for your quick and helpful reply. I’ve been able to apply this to my other data as well now. Do you have a tutorial for applying this same concept to different series of data so that the shading under each series line is a different color?

Here is the same raw data that I am working with. I am trying to shade the area under the data points measured prior to treatment in a different color than the data points measured after treatment.

Weeks Prior to Treatment After Treatment
-1 283
-0.43 249
-0.29 271
0 260 260
0.57 105
0.86 108

Thank you again for your help, Jon!

- Rebekah


Comment from Jon Peltier
Time: Saturday, May 1, 2010, 2:05 pm

Rebekah -

The workbook now contains both variants of this problem:

Rebekah-XYArea.xls

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.