So you’ve made it to part 3 of Are You Trendy, well done.
In todays final post of Are You Trendy? we will take a break from the maths and discuss techniques and tools that Excel provides to assist us with Trend Analysis.
We will look at 2 techniques, one built-in to Excel called Charts and another which is a User Defined Function (UDF) I developed.
Both techniques have uses in analysis of trends.
Once again all examples below are found on the Examples Workbook.
Excel Charts
Excel has a number of charting styles some of which have the ability to calculate and display Trend Lines.
The following tables shows which charts Do and Don’t support built-in trendlines.
Supports Trendlines | Doesn’t Support Trendlines |
Scatter (X Y) | Pie |
Line | Donut |
Area | Radar |
Column | Stock |
Bar | Surface |
Bubble |
For those charts that don’t support trendlines, this doesn’t stop us, as Excel users, from adding other series or using other techniques to add trendlines to the charts, it just that we have to do the hard work ourselves and not use Excels built-in skills.
For this exercise we will be using a Scatter (X Y) Chart but the techniques apply equally to all charts that support trendlines.
So lets go: First we need some data.
Next add a scatter chart , Select the data and Insert Chart, X Y (Scatter Chart)
Adding a Trend Line to the chart is as simple as selecting the chart and right click on the Series you want to add the Trend Line to, see below.
You can change the trendlines properties to make it stand out as per the above.
Once you add a Trendline a Format Trendline dialog will appear.
This is the main window for setting Trendline properties and format options.
In this post I am not going to be dealing with the Tab Options of Line Color, Line Style, Shadow and Glow and Soft Edge options, as I am sure you can work out what they do and play with them at your leisure.
Trendline Properties
Once you have added a Trendline you can access the Trendlines properties at any time by:
Selecting the chart
Select the Trendline
Right Click and Format Trendline.
How Many Trendlines Can I Have ?
You can add a large number of Trendlines to each Chart Series in Excel by simply selecting the Right Clicking on the Chart Series and select Add Trendline.
Some of the regression types may not be available on second and subsequent regressions.
Trend/Regression Type
The main section of the Format Trendline dialog is the Trend/Regression Type:
This section lists 5 trend types we are familiar with from the Are You Trendy? (Part 2).
For more details on the individual Tren Types refer to Are You Trendy (Part 2).
The default trend type is Linear ( Y = mX + c ).
You can select each type in turn and see the estimated trend.
Exponential
Linear
Logarithmic
Polynomial
This shows the Trendline for a Polynomial Estimate of Power = 2. Excel supports up to Power = 6.
Power
Moving Average
Moving average isn’t a forecasting tool, but is more of a data manipulation tool, which is commonly used for elimination of short term trends or smoothing of the data source. Some industries use Moving Averages to look at buying and selling opportunities by comparing the current price against longer term trends.
It is possible to use moving average data for trend analysis, but this must be first done manually in Excel and then it can be used with the techniques discussed here.
As such we won’t be discussing its use here.
If you are interested in reading more about the use of moving averages have a look at Moving Average.
Trendline Name
The Trendline Name section by default shows you the Selected Trend Estimation type and your Data Series Name eg: Linear (My Data)
However you can type whatever Name you want by using the custom field:
eg: Huis Fruit Shop Sales Trend
Forecast
The Excel Chart Trendline function allows us the option to project our Trendline a number of periods or X Values into the future or past.
The above will forecast our trend line 50 X axis values past the limits of our data and 10 X axis values prior to the limits of our data and is shown below.
This is a great option to use for 2 reasons.
Firstly you can use this to see where the Trendline will cross the Y axis (X = 0) and is an important check to validate your selected Trendline.
You can see in the example above that the Trendline crosses the axis at -10. If this isn’t correct we can either try another estimation technique or Excel has a tool, which is discussed below, to deal with that.
Secondly, you can use it to look into the future by projecting the Trendline past your data limits.
Misc Parameters
The final 3 parameters
Set Intercept
By default Excel Chart Trendline has used a Const value of True and hence calculates the natural intercept value for the data. If you want to over-ride this with a 0 intercept value Tick the box and select a value
Set Intercept : Not selected
Set Intercept : Selected Value of 10.0
I would always suggest using the Forecast backwards option first to see what the natural intercept is before using this option (Both charts above show the Trendline projected back 10 periods) but the second chart has a Y intercept set manually to 10.
Display Equation on Chart
The Display Equation on Chart options use is self explanatory, it Display the equation to the current Trendline on the current Chart:
The equation is based on the select Trend type.
The equation is also live, in that if you change and selected another Trend Type or the data changes the equation will update, similarly if you select to intercept the Y axis at 0 or another value.
By selecting the Text Box which has the equation the equations Font properties can be changed eg: Font Style, Size, Italic, Bold etc as well as background color.
Display R2 on Chart
This display the R2 value on the chart in the equation Text Box as shown above.
The R2 value is based on the select Trend type.
The R2 value is also live, in that if you change and selected another Trend Type or the data changes the R2 will update, similarly if you select to intercept the Y axis at 0 or another value.
By selecting the Text Box which has the equation the R2 the Font properties can be changed eg: Font Style, Size, Italic, Bold etc as well as background color.
How Can We Look at Values Along a Trend Line?
In Are You Trendy? (Part 2) and in the section above we looked at a number of ways of establishing a Trendline.
So how can I predict values along a Trendline?
There are a few ways and we will discuss 2 of them.
1. Write an equation in excel
2. Use my Trendy User Defined function.
Write an Equation in Excel
In the previous section we had a chart shown below:
The equation for the line of best fit is Y=7.8984.e^(0.0256.X) which in Excel cell formula talk is =7.8984*EXP(0.0256*X Cell)
So we can setup a cell or range of cells in excel to show us either intermediate values or future values of X and the corresponding Y values.
The great thing about having an equation is that we can now use this to animate our chart.
I’m not talking about Avatar style animation, but simply adding a tool for the user to interactively select X values and the equation and chart will show us the new Y value. This even allows us to show future values past the end of our data because we are using the equation to our data.
How do we do this?
Refer to Sample Workbook.
Firstly lets add a cell which will contain the X value
E52 = 10
Secondly add a cell which has our equation
E53: =7.8984*EXP(0.0256*X Cell)
Third add a Scroll Bar Control from the Active X controls on the Developer toolbar and set a few properties
Minimum = 0
Maximum = 300
Linked Cell = E52
Large Change = 10
Fourth add a new series to our chart which will just have a single X and Y value
Series Name = “Our Trend”
X Series = E52
Y Series = E53
You can now interactively move the srcoll bar back and forth and the Chart will show you the new forecast value for our sales in Huis Fruit Shop.
The limitations with the above approach is that it is fixed to the equation you use for your Y value, which is based on your selected choice of Trendline type.
Can we link this technique to the equation from the Trendline ?
With Excel natively, No 🙁 .
TrendY – A User Defined Function for the Analysis of Past, Intermediate & Future Trendline Values
In a post at Chandoo.org user Trevian3969 asked the question “How can I view intermediate values along a Charts trend line?”
The answer was the development of the UDF, TrendY (Trendy).
Trendy was developed to do exactly that, take the equation from a Charts Trendline and evaluate it to determine intermediate, past or future values based on a given X input.
Because the UDF is taking the equation for the trend line it can be used to return a Y value for any X values, prior to, later than or within the supplied or known X Range of the chart.
An Example of the use of Trendy is shown in the attached Workbook
Form: = TrendY(X Value, [Chart No], [Series No], [Trendline No])
X Value: Is the X Value that you want to know the Y Value of the Trendline
Chart No: Chart No is optional and is the Chart No on the current sheet, Default or omitted = 1
Series No: Series No is optional and is the Series No on the chart, Default or omitted = 1. The series No is the number shown at the end of the Formula Bar when a series is selected
eg: =SERIES(“My Data”,Sheet1!$B$2:$B$41,Sheet1!$C$2:$C$41,1)
Trendline No: Trendline No is optional and is the Trendline No of the Trendline you wish to track. Default or omitted = 1.
[Option Parameters, Default = 1]
Eg: = TrendY(20) will place the value of X=20 into the Trendline Equation of the Trendline of Chart 1 Series 1 Trendline 1
= TrendY(40,1,3,2) will place the value of X=20 into the Trendline Equation of the Trendline of Chart 1 Series 3 Trendline 2
=TrendY(B43,,3) will place the value of cell B43 into the Trendline Equation of the Trendline of Chart 1 Series 3 Trendline 1. Chart and Trendline both default to 1 as they are omitted.
The function works with all the Trendline types and variants of those, except the Moving Average.
To use the Trendy UDF copy the following code to a VBA Module or alternatively import the Txt File as a new Module
The code is also available in the Example Workbook with a fully working m0del.
If you don’t have the Trendlines equation shown it will do that for you and it ignores the R^2 function if shown.
The Trendlines equation box is actually where the function gets the equation from in the first place.
Then on a worksheet simply use then =Trendy(X Value) as described above.
Trendy has only been tested on Excel 2007 and 2010, use on other versions at your own risk.
Limitations
The Trendy UDF is limited to use the available precision of the parameters, for each equation, as displayed in the Equation Text Box on the Chart.
In some cases especially when multiplying by powers of large numbers and especially in the Polynomial equations, there may be a large discrepancy between the calculated value by Trendy and the displayed value by the Trendline on the Chart. In these cases the Trendline is correct. This will show on the chart as the Plot Y value of Trendy not being on the Excel calculated Trendline.
Trendy has 2 constants at the top of the UDF that are used for the calculation of Intermediate Equations. These are equations that the user doesn’t see but are done at a much higher level of precision to avoid these errors. These constants are:
Const DataLabelNoFormat = “#,##0.0000”
Const PolynomialNoFormat = “#,##0.000000000000”
If you have rounding errors the easiest way to fix them is to increase the number of decimals by increasing the number of zeroes after the decimal in the appropriate line, remembering that Excel only carries 15 decimal places anyway and Trendy is already using 12 for Polynomial Trends already.
Trendy returns the displayed equations to 4 decimals after the intermediate calculations in any case.
Further Readings
All Examples from the Are You Trendy? Series in one Workbook
Final
I hope you have enjoyed this 3 part series on Trend Analysis and Forecasting using Excel.
It has been put together to Introduce you to, and whet your appetite to, some of the functions, tools and techniques that you may not have had a lot of exposure to in the area of Trend Analysis and Forecasting using Excel.
I’d like to thank Chandoo for the opportunity to look after Chandoo.org for the past week and the opportunity to put the 4 posts up.
I will now hand Chandoo back the keys to the blog, hopefully without any dents.
Let me know what you thought of the series in the comments below:
Keep us informed on How you go with real data once you start applying some of these techniques.
Hui…
ps: I still don’t know if Trevian3969 was happy with my response to his post as he never responded ?
63 Responses to “Custom Chart Axis Formating – Part 2.”
Hui, these are cool little tricks. Not one I need today, but well worth remembering for future dashboards
I recently learned what I thought was a really simple but useful number format. A custom format followed by ;;; will not display 0 values. Example format #,##0.00,,;;; will display 12,570,000 as 12.57 and display 0 as blank. I found that this really helped me reduce some of the clutter on dynamic charts. Thanks for another good article.
Like! 🙂
hi Hui,
Once I have created a custom format, how do I remove/delete it from the list again? I tried a few methods such as right click (no option to remove). I tried hi-lighting the custom format and hit the delete key. Nothing works.
@Fred,
Unlike the Custom Number format dialog for cells they don't have a Delete Button on the Chart Number Formats dialog, Maybe next version?
.
If you don't want to use your Custom Format select one of the built in formats.
hi chandoo and all,
great tips on the formatting.
1 curious answer: Is it possible to highlight Sat/Sun for DATES on x-axis?
assuming i have 1 month of daily product sales, x-axis = dates, y-axies = sum of sales.
thanks!
@Davidlim
.
You have limited options here as you can only use 3 conditional ranges in the [ ] brackets
So you can do something like
[Green][<40787]ddd;[Blue][>40788]ddd;[Red]ddd
This will make:
Dates earlier than September 2011 Green
Dates after September 2nd 2011 Blue
Dates on September 1 or 2nd, 2011 Red
.
Otherwise you can use the techniques where you use a Combination chart and color the weekend column a highlight color to emphasize them
Have a look at: http://chandoo.org/wp/2009/08/26/combo-charts-to-group-times/
Download the file just below:
Download this excel combo chart and play with it to learn more
Select the hidden bars and apply a fill
Great post,
I would like to know a way to apply custom formatting to the horizontal axis.
Suppose, I want to highlight F,G & H in Red
@Fowmy
As far as I'm aware it can't be done using Custom Formats
You can of course use cells lined up under the chart and do the Conditional Formatting in those cells
@Hui:
How do I get the number formats to work on a Dynamic Chart.i.e: Chart with different scaling based on different data sources. For example, if I have five KPI and each have a Target, how do I get the chart to dynamically change number format based on the data selected?
@Donald
Have a read of this Forum and my comments and see if that helps you
http://chandoo.org/forums/topic/making-vlookup-recieve-multiple-formats-of-data
@Hui: Thanx for the speedy comment, I've checked the link and your last comment is almost what I need but I can't get it right for my application. See below my problems. Data below is displayed on the dynamic graph. The Graph only shows two data lines Target and the actual KPI data. on the data line I won't to highlight the numbers based on the info below relative to the Target line.
KPI Target GREEN ORANGE RED
DCR 1 and 1.2
BSS Setup 99 >99 95> and <99 <95
TCH BLK 0.5 and 1
SD BLK 0.5 and 1
UL_TBF S_Rate 90 >85 85> and <90 85 85> and <90 <85
@Donald
Do you want to email me this file
I'm struggling to visualise this
add instructions please
I remember seeing a blog post some time ago about the number format colors. The default green color is ugly, and there was some neat trick to change that into more dark green version. I think it had to do with assigning some code instead of [green].
@Hui: I just forward you a mail now. I've also noticed that the custom only allows two conditions and I struggling to put more custom for same chart. As indicated, the graph has different target format i.e 1% and 95%.
@Donald: I'm not sure what do you want to get in your case, here is what I've used in my dashboard for different KPI values:
[50000]$#,K;0
I have %'s, monthly sales amounts (all > $50000) and invoice counts. However I didn't apply this formatting to the axis number format - it will always have 0 as 0.00% - any ideas how to avoid this?
Formatting in my comment above should be as following: [50000]$#,K;0
one more time:
[50000]$#,K;0
@Oleksiy: Follow link on Hui comment (11). Looks like it might address your problem.
@Donald: I have done similar for series values already, just for some reason Chandoo's website modified my comment from "/<1/0.00%; /50000/$#,K;0" where / - [ and ]. 🙂
Problem is that I can't apply this to the axis format as it always has zero.
Thanks, Hui.
Hello Hui, Please suggest how can I highlight ( making it bold or colored) a particular month among 12 months that I put in X axis.
You can use the same technique with Dates that are Dates, but not when they are Text.
That is if your X-Axis has dates, apply a custom number format like
[Red][<=40790]d-mmm;[Black]d-mmm
that is Dates <= 4 Sept 2011 will be Red, others will be Black where 40790 is the serial number for 4 Sept 2011 You can change the Date Format d-mmm to whatever suits you . [Red][<=40790]d-mmm;[Black][<40798]d-mmm;[Green]d-mmm
Red <=4 Sep Black < 12 Sep Green >= 12 Sep
.
The Date fomats can change as well
[Red][<=40790]d mm;[Black][<40798]d-mmm;[Green]d mmmm yy
Red <= 4 Sept; displayed as 4 09 Black < 12 Sept; displayed as 12-Sep Green >= 12 Sept; displayed as 12 September 11
Thanks a lot Hui for your great suggestion. So it is only possible for months not for any other texts!
@Tamoghna
Its possible for any Numbers, %, $, Dates or Times,
Which are all numbers anyway.
It is not possible for Text
If you need to do text, you can consider using Text Boxes or cells behind the chart where you can apply conditional formats to.
So instead of using the Built In axis labels, make the chart transparent and place a number of Columns behind the chart with the approriate text and Conditional Formats in it
A similar approach can be done using Text Boxes linked to cells
Hui,
This is great and very timely because I suddenly have a need for lables that change format according to the values - so thank you.
A quick question however, on a slightly different issue. Is it possible to format the markers so they don't show for a zero value but do show for any value above or below zero.
Thanks,
Linda
@Linda
try a format like
[red]0;[green]-2;;
.
Note the custom format layout is
Positive;Negative;0;Text
.
so by having a third parameter of ;;
you get no format when it is 0
Hui,
Thanks for the quick response. However, I don't seem to know where to type the format. I can see how to do this for the Labels but not for the actual graph marker itself. Esentially I want the marker to show if there is a value, but not if it is 0.
Appreciate your help.
Linda
@Linda
Sorry, I'd misread your requirements
Where your data is, change the formula to be
=if(my formula=0, na(), my Formula)
.
You may have to change the settings
Select chart
Right Click, Select data
Hidden & Empty cells
Adjust to suit
Hui,
Thank you so much that worked well. I had a couple of problems at first because I had the graph type set as a line and the #NA had no effect. However, once I changed it to XY scatter, your suggestion worked like a treat!
Thanks so much for your help
Linda
@Linda
You may want to also have a read of
http://chandoo.org/wp/2010/11/11/highlight-data-points-scatter-line-charts/
Hello Hui,
I have a data validation cell (A1) with a dropdown list for "Qty" and "$$$".
My data set is values that I plot asa Pie Chart (In Column B1).
These values are conditionally read from 2 different tables depending on the drop down list selection for $$$$ or Qty.
I have conditionlly formatted all cells in B1 to display number format as Number (0 decimal places) or Currency $ again dependent on selection made in A1.
Now my pie chart is updating correctly based on my selections and data but the labels do not get formatted to Number or Currency automatically.
How can I conditionally format the labels based on selection in A1?
@Aashtee
You can't conditionally format chart objects against another cell only against there own values.
If the values for Qty and price are different
ie: Price $100-200
Qty 1-20
you can use a Custom Number format like
[Blue][>=100]$#,###.00 ;[Red][<100]#,###;
.
But if they overlap it can't be done
[...] http://chandoo.org/wp/2011/08/22/custom-chart-axis-formating-part-2/ [...]
Hi Hui,
I'm trying to customize the x-axis from 0,1,2,3,4,5 to read: 0, KG, 1, 2, 3, 4, 5. How can I do this?
Also, the x-axis figures are currently on top of my chart, how can I move these to be on the bottom?
Thanks!
@Annie
Try the following Custom Number Format
#;-#;0" Kg";@
Thanks! This almost works perfectly, except that the "0" and the "KG" are labels for the same point (0). I need the "0" at 0 and then "KG" then 1, 2, 3,...
Thank you for your help with this!
Select the X Axis
Ctrl 1
Axis Options Tab
Vertical Axis Crosses
Axis Value: 0.0
That didn't change anything.
To clarify, I'm trying to get the x-axis to read: 0 KG 1 2 3 4 5 (evenly spaced). The problem may be in trying to put "KG" in the "1" place, "1" in the "2" place, and so on.
Annie
What type of Chart is this ?
It's a clustered bar chart that I'm using to show when curriculum was developed for different subjects. The y-axis indicates the year the curriculum was developed and the x-axis corresponds to the grade level (KG is short for kindergarten, followed by Class 1, 2, 3, 4 and 5).
@Annie
I'm struggling with an easy solution for this one
One way would be to delete the axis altogether or use a Custom Number format like ;;;
Then setup a manual set of cells with the 0 K 1 2 3 4 etc which would be located behind the chart and then resemble the Axis Labels
or
Setup a Text Box/es with the same Sequence 0 K 1 2 3 4 etc and place that where the axis would be
Once properly located and sized, The Text Box could be grouped with the chart so that they remain fixed to each other.
Hi Annie,
I think this might work for you...basically what Hui said but a couple small tweaks.
use this custom format
General;[<0]"0";"KG"
It will make negatives appear as 0 and 0 appear as KG, positive numbers will remain as they are.
Then select the x-axis and ctrl+1 to go to format axis.
Axis Options
1/Set Minimum to -1 (Fixed)
2/Set Maximum to 5 (Fixed, optional)
3/Vertical axis crosses; Axis Value = -1
In your data, make sure that all data points relating to KG are 0.
Your clustered bar chart should have 0 KG 1 2 3 4 5 for the x-axis labels.
Kyle
THANK YOU SO MUCH!
This worked perfectly. I really appreciate all of your help.
Phew!
Annie
minor note on the customer format I posted...it doesn't need the [<0] in General;[<0]"0";"KG". You can just use General;"0";"KG"
hi drea,
thank you so much !
i am from iran.
this site is very good for me.
this site has very good information from excel.
by
I need to do something like your highlight thousands as K, but to this degree:
1? 0.000001
10? 0.00001 100? 0.0001 1m 0.001 10m 0.010 100m 0.100
1 1.000
10 10.000
100 100.000
1k 1000.000 10k 10000.000 100k 100000.000 1M 1000000.000 10M 10000000.000 100M 100000000.000 1G 1000000000.000 10G 10000000000.000
100G 100000000000.000
From what i've been told i can not express all of that as a chart label number format, so i was looking at other options.
Within VBA and Excel, how can i apply a NumberFormat like this to a chart?
Any help is greatly appreciated!
Russ
Actually the numbers ghot screwed up when i pasted.
They should be like
1K 1000.0
10K 10000.0
100K 100000.0
etc.
If it is just "k"s that you want to add, then using the format #,"k" should work.
My y axis goes from 0 to 1 with increments of 0.1
I want it do be displayed in terms of p10,p20 all the way to p100
For ex instead of 0.1 i want p90 and instead of 0.2 i want p80 all the waiy to p0. Is this possible?
@Yousuf
You can't do maths in Number Formatting apart from the Power of 10 tricks discussed here: http://chandoo.org/wp/2012/01/31/custom-number-formats-multiply-divide-by-any-power-of-10/
However you can still do what you want
Setup your chart
Select the Y Axis and set Max to 1, Min to 0 and Major Unit to 0.1
With the Chart selected Add text boxes and type the text you want for each Axis Point eg: p10, p20 etc
Locate the text boxes in the correct locations using the Axis as a guide
Set the text size, font, Bold etc to suit
Select all the text boxes and group them
Select the axis and set the text color to None
How can I use an image instead of a text on chart axes? I would like to use companies logos instead of using the names on x-axis. Is it possible?
@lonchas
With the chart selected
Select the axis
Set the Custom Number format to "";"";""
This will display the axis without labels
Then paste the pictures in, rescale and position as appropriate
Is it not possible to insert the picture automatically, just associating each label with a picture?
I am trying to do something like that:
http://www.ricaperrone.com.br/2012/09/br12-publico-e-renda/
(pls, see the third image).
I though the images had been inserted directly from cells through a formule.
I have data labels in percentage format. which custom format i should use to have green color fornt if more then 100% and red color font if less then 100%.
@Bisal
try:
[>1][Green]0%;[<=1][Red]0%
I'm hoping you can help. I have a dynamic chart for financial data. Most of the charts have a y axis based on $ with a couple charts that are a %. I can not use a option mentioned above since some of the $s have a negative value. I tried conditional formatting the source, but the 'Link to source' does not pick up the conditional formatting. Is there a way to have the y axis dynamically change from $ to %. I am using a combo box to change the data on the chart.
@Shelley
Can you post or email me a sample file ?
I emailed the file. Did you receive it?
I need this question to be answered for me too. My "linked" data is conditional formatted to be red given some criteria. I want my axis to be red too, but it only picks up the number format, not the conditional formatting.
The “linked” data from my table is conditional formatted to be red based off of some criteria. I want my chart axis to be red too, but it only picks up the number format, not the conditional formatting.
Is there any way to link conditional formatting of sourced data to axis labels?
You are awesome chandoo. Thanks
Hi Chandoo,
Your posts are very helpful.
Is there a way to conditionally format the data label position/location (in addition color, as you have shown in this post)?
I have some line charts with markers showing the same measure from year to year. Each chart has two lines. One of the lines is an average of participants in the group and stays the same. The other line is for each participant and gets updated dynamically to produce about 50 unique charts total. If I put the data labels "above" or "below," they look good for about half the participants, then overlap or are confusing next to each other for the remaining half of the participants (given that the one line is the average of all participants). Right, left, and center do not look good, as they overlap the lines. I tried using the Chart Tools---> Design---> Style 2, which makes the markers bigger and places the data label inside the marker. However, for the 3-4 participants per year who have about average values, the marker for the participant overlaps with that for the average and makes the labels unreadable.
Thank you for any help you can offer!