Colors in Chart Labels [Quick Tip]

Posted on January 29th, 2009 in Charts and Graphs , Learn Excel - 18 comments

This post is part of our spreadcheats series – 30 Excel and Charting Tips & Hacks aimed to make day to day spreadsheeting fun and productive.

One of the most common charts is “YoY Growth Rates of Our Superawesomekickass Product”. While not everyone may have a superawesomekickass product, most of us in fact make a YoY (Year on Year) growth rate charts for various types of data.

A simple label formatting hack can improve the effectiveness of these charts by adding color to differentiate positive vs. negative growth (or mediocre vs. sky rocketing growth rates). See this example:

Excel Chart - Colors in Data Labels - How to

You can get this effect by applying custom number formatting to the data label. It is one of my favorite tricks in excel and I have written about it in introduction to custom cell formatting in excel, number formatting in excel using custom codes, showing decimal values only when needed articles.

How you can get colors in Axis Labels

First apply data labels to your chart and now select the data labels and press ctrl+1 (aww, come on now, you are reading this blog, you should what ctrl+1 means) and go to numbers tab. Select “custom” as category and specify the formatting code like this:

custom format code for getting colors in chart labels

[blue]+0%;[red]-0%

Now, that was easy, isn’t it. But you might think, “Chandoo, what the heck the above format code is doing?”

Well, it tells excel to apply red color and add a minus symbol if the data label value is less than zero and apply blue color and add + symbol if the value is above zero. You see the custom number formatting codes have 3 parts in them, like this:

formatting for positive numbers ; formatting for negative numbers ; formatting for zero values

If you are noob (hi noob!) and lost in all these codes and square brackets, you may want to checkout our post on introduction to number formatting in excel to learn more about custom codes.

Ok, that was fun, What else you can do?

You can do much more using custom codes to format data labels. For example, a code like [Red][<0.15]0%;[Blue][>=0.15]0%; will, Oh, forget it, you can guess that. Just remember that excel allows only 3 parts in custom codes. So go nuts, but just thrice.

Like this post, I mean REALLY like it?

Awesome, You should  sign up for e-mail updates or get our full RSS Feeds so that you never miss a post.

Why you should never miss a post? Because my friend, one of the posts might help you make your product superawesomekickass.

| More
Subscribe for PHD Email updates and get a free excel e-book with 95 tips & tricks

Comments
Sam Krysiak January 29, 2009

I’ve been looking for a way to include colour-coded chart labels without applying the formatting manually. Great tip!

Sumit Dhar January 30, 2009

Chandoo, it is possible to format the bar colors in the chart based on the values?

Cheers,
Dhar

derek January 31, 2009

Sumit, the trick is to use lateral thinking and create two bar series: one colour is when you want it blue and zero when you don’t, and the other colour is the other way round.

Chandoo February 1, 2009

@Sam: thanks
@Sumit: as Derek suggested, the trick lies in creating multiple series and completely overlapping them so that you see color as per your need.

Govert February 4, 2009

Superb tip! Thanks!

Sumit Dhar February 6, 2009

Derek / Chandoo,

Thanks for your inputs.

Cheers,
D.

David H February 19, 2009

Chandoo,

Can you provide an example of this:

“@Sam: thanks
@Sumit: as Derek suggested, the trick lies in creating multiple series and completely overlapping them so that you see color as per your need.”

Thanks!
David

Chandoo February 19, 2009

@David: Sure, I will make a note of this topic and write about it in the coming weeks :)

David June 5, 2009

A few weeks ago, Chandoo posted some Excel Tips and mine was one of those tips. I created a KPI spreadsheet that changed the format of numbers and the colors of the chart based on the table of data below the chart. (See original post: http://chandoo.org/wp/2009/05/11/excel-tips-by-you-1/). Maybe this would be helpful. I still want to post a blog entry on this but due to budget problems in our state, I don’t have the time. Soon…

Vanessa June 5, 2009

Hi Chandoo!
Is there a way I can make the labels show white doing this? I tried [White]-0.0% but it gives me a white font with a black background… I wanted the labels to be “invisible” in case it is less than zero!

Chandoo June 5, 2009

@Vanessa.. you can do that by using a formatting code like 0.0%;;0% (the middle portion of the formatting code tells how negative numbers should be shown, and we are telling excel to show nothing if the number is negative)

Also, the if you want use the WHITE color, then you need to set the label background color to transparent. This can be done by selecting labels, hitting format labels option, and then in the label background color area (from font tab) you can set the background color to be transparent (the default value is automatic or something like that…)

sonato June 24, 2009

hey!
Its very good
when I first saw it, I said: oh but this too, I could do it easily manually
but when I did it, I really saw the beauty that accompanies it.
Thanks

jeremy June 29, 2009

i want to setup conditional formatting on a chart label, based on a cell that is not a part of the data range. i.e. i want the 90% label on a bar chart to be bold and underlined when cell A1=1, when cell A1=0 no formatting.

is this possible? (excel 2000)

cheers

Chandoo June 30, 2009

@Sonato: Thank you :)

@Jeremy: Welcome to PHD and thanks for commenting. I am not aware of a simple way to conditionally format axis labels. You can try using some macros though. But the best thing would be use as few colors as possible. This looks both aesthetically pleasing and takes less time.

keith August 31, 2009

Hi Chandoo,

I am making a line chart to display numbers between 0 and say 30. I have upper and lower limit lines at 4 and 10. What would be the easiest way to make numbers outside those limits display red while leaving the numbers between 4 and 10 green. I am new at this and tried entering custom functions/formulas but cant get it right.

Thanks
P.S. Excel 2003

RSS feed for comments on this post. TrackBack URI

Leave a comment

   Name (required)

   E-mail (required, never displayed)

   URL


If you have a question, please ask in the forums

Recommended Excel, Charting, VBA books