Update [10/21/2009]: version 1.1 is available for download (see links below). Remember to set the jQuery path and the pictures path in the script before using it.
Craig Lowrie is a Network administrator at the Ear Science Institute (Australia). A couple days ago, he shared with me a very useful script, allowing to add color coding to SharePoint Gantt views.
Let’s start with the live demo (combined here with the Gantt slider):
http://www.pathtosharepoint.com/Gantt/
A SharePoint Gantt view is made of two sections: the Gantt view itself (not customizable), and underneath a “summary list” that displays the task properties. We have customized this view to display the priority levels.
Craig’s script works as follows:
- first, it scans the summary list to identify for each task the priority level.
- it then goes back to the Gantt view, and for each task it replaces the blue bar with the appropriate color (red/yellow/green). This is done by replacing the dozens of small blue images that make the Gantt view with custom images (yes, SharePoint uses one image per day!).
The files for this customization are available on my site’s download page (to download a file, right click on it and select “save target as”).
First, you’ll need to unzip BarImages.zip, and place the images created by Craig in a library.
Then you’ll need to place the script on the page that contains your Gantt view. You have two choices on the download page:
- either the script (ColorCodedGantt.txt) that you’ll paste in the source editor of a Content Editor Web Part
- or directly the Web Part itself (ColorCodedGantt.dwp) that you can import to your SharePoint page.
The last step consists in minor adjustments to the script:
- change the path to point to the library where you stored the images (PicturesPath in the script)
- The sample code calls the jQuery library available online from Google. You may want to link to your local jQuery library instead. Or remove the call if you already use jQuery on your page.
You can easily adapt the script to work with a choice list other than Priority. Simply replace (High|Normal|low) in the script with your own values.
Thanks for sharing Craig!


66 comments
Comments feed for this article
September 10, 2009 at 1:50 am
kaboilek
Hi Christophe, this is great but what I am trying to do is implement this to a schedule versus a task list. Therefore using Regions instead of Priorities. My question is where exactly do we place the images? Is it at the site level or at the collection level. I have created a picture library within the site of the schedule and used the url and the image are not showing up. I believe I have everything else working per your instructions.
Thanks in advance.
September 12, 2009 at 3:41 am
Christophe
The place where you store the pictures doesn’t really matter, as long as the users have read access. It could even be a Web site outside SharePoint.
Using regions? so you must have created a choice list like this:
(1) Region1
(2) Region2
(3) Region3
and changed the script to:
var regex = /\(\d\)\s(Region1|Region2|Region3)/;
September 12, 2009 at 10:25 am
kaboilek
Actually I added 5 and yes changed the regex to = the regions. I did add (#) as well. I will attempt another try and keep you posted. Thank you for the help.
September 16, 2009 at 12:17 pm
Sriram
Hi Christophe
Thanks for the intuitive idea to color code Gantt chart. I have extended the technique to highlight overrun tasks. http://www.iotap.com/Blogs/tabid/277/EntryId/115/Highlighting-Overrun-Tasks-In-Sharepoint-Gantt-Chart.aspx
Thanks
September 17, 2009 at 1:33 pm
René
Hello,
I’m trying this great feature but i cant get it working. Somehow the sliders pictures won’t show. I did as described but still it not work. when I right click on the the red cross (supposed to be colored sliders) I saw that the pictures don’t have numbers at the end? any help appreciated. Thanks!
September 17, 2009 at 1:53 pm
René
Nevermind i got it working i think this was a translate error since im using the project site in dutch.
September 21, 2009 at 11:49 am
Umka
hi Christophe!
i think i’ve followed all your inspiring ideas! they are great! i’m trying this with gantt view (thinking of absence calendar) but for some reason instead of pictures have same as Rene – red crosses. must be my image library not visible. cant find what it can be.
all users has read access to page and to library. any ideas? maybe there are some else restrictions to it?
September 22, 2009 at 12:03 pm
Christophe
Well, René has fixed his issue. I suggest that you right click on a red cross to see the properties, it’ll tell you what the browser is looking for.
September 22, 2009 at 5:25 pm
kaboilek
Hi Christophe,
I finally got around to see if I can get the images to appear and still no luck. Doing as you state above to Umka it is looking for StartNormal but it isn’t picking /StartNormal0.gif, /StartNormal1.gif etc. this is what it shows: StartNormalundefined.gif.
I have used the following for my choices:
(1) Central1
(2) East2
(3) Gulf3
and var regex = /\(\d\)\s(Central1|East2|Gulf3)/;
and I still am not able to bring up the images… I am so close darn it. What am I overlooking?
September 23, 2009 at 9:03 am
clowrie
Make sure you’ve add the column containing your regions to the gantt view. The region must be displayed in the table below the gantt chart for the code to work.
September 23, 2009 at 10:51 am
kaboilek
Hi clowrie, yes the columns that I have tried to use with the script have been included in the chart below the gantt. As of late yesterday I was able to bring up some of the images for the graph (I did a view source on Christophe’s gantt chart from the link above and copied the script from there) but not for all. I changed the column Region (using 5 choices) to Health only using 3 choices (Critical | At Risk | On Track) and only 2 of the images appear images1/CenterNormal3.gif and images1/CenterNormal2.gif.
I wish I could past the screen shot to show what it actually looks like.
September 23, 2009 at 11:15 am
kaboilek
Here is the code (which I included within the CQWP or the webpart from Christophe at the bottom of the gantt webpart):
$(function(){
// URL to the bar images
var PicturesPath = "/sites/AO/ivstechplanner/images1";
// Collect the priority level for each task
var barColours = new Array();
var regex = /\(\d\)\s(Critical|At Risk|On Track)/;
// Find the tasks summary list
var TasksList = $(".ms-summarystandardbody>tbody>tr:not(.ms-viewheadertr)");
if (TasksList.length == 0) TasksList = $(".ms-listviewtable>tbody>tr:not(.ms-viewheadertr)");
TasksList.each(function(i){
try {
barColours[i] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err){}
});
// Modify the bar color according to priority
$(".ms-ganttTaskRow").each(function(i){
$(this).find("img").each(function(){
var source=this.src;
source = source.replace(/.gif/, barColours[i]+".gif");
source = source.replace(/\/_layouts\/images/,PicturesPath);
this.src=source;
});
});
});
September 23, 2009 at 2:00 pm
clowrie
Hi kaboilek, if you check the image properties (right click on the red X image place marker) and select properties, is the image name still showing up as “StartNormalundefined.gif”? If not verify that the image can be accessed directly by typing the path and filename directly into your browser ie: http:///sites/AO/ivstechplanner/images1/StartNormal1.gif
Also make sure your choices are exactly:
(1) Critical
(2) At Risk
(3) On Track
Check all capital letters (the code is case sensitive), and make sure there is a single space between the “)” and the first letter.
September 24, 2009 at 12:08 pm
Christophe
My two cents: maybe your issue is due to spaces in the names. Try replacing spaces with \s in the regular expression:
var regex = /\(\d\)\s(Critical|At\sRisk|On\sTrack)/;
September 24, 2009 at 12:35 pm
kaboilek
Okay I will try that but then why did it not work with the region? You know what would it make a difference if this was Intranet versus Internet?? I remember reading something about Web 2.0 not friendly with Intranet.
September 25, 2009 at 5:51 pm
kaboilek
Good News!
Wow you are not going to believe what was causing my issue and I had no idea that it would affect the script. I had the below table grouped by region by project. When I took the group selection away all the colors came into play in the gantt chart.
My next question is can we modify the script so that if you do group bys the script will work? No biggie but that would be awesome especially if you have over 100 items…. Anyway thank you one and all for the help!
September 25, 2009 at 7:43 pm
kaboilek
I also found out that the script will not work if you use the gantt within a web part.
September 26, 2009 at 5:02 am
Christophe
oh yeah, with this sample script, rows in the table have to match the rows in the Gantt, so the extra rows used for grouping will mess things up.
Sorry, I don’t get your last comment…
September 28, 2009 at 10:49 am
kaboilek
On my default page I have 2 web parts, one for the gantt and then one for your script. The colors do not appear when I have the page setup this way.
October 7, 2009 at 1:55 am
Christophe
Kathy, Craig and I are working on an updated version that should be easier to deal with. Please stay tuned, and thanks for your patience!
October 7, 2009 at 1:32 pm
kaboilek
You and Craig are wonderful!! thank you and I will stay tuned to this
October 14, 2009 at 1:28 am
clowrie
kaboilek, send me an e-mail: crlowrieATgmailDOTcom and I’ll see if I can help sort out your code issues.
November 1, 2009 at 6:25 am
Javed Khalid
Hey Guys,
I have tried using it but all in vain. If I insert a new content editor webpart it does not work, and i am unable to find the import for the .dwp file.
Please help!
Thanks
November 1, 2009 at 10:38 am
Christophe
There’s a tutorial for the import option on the Bamboo blog.
Color coding works fine on my demo page. Could you be more specific about your issue?
November 2, 2009 at 10:58 am
Javed Khalid
I am using the Gantt Chart for displaying vacation status and trainings in my website. I created this list using the “Project Tasks” under “Tracking” in the “Site Actions” —> “Create”
I want to display the vacations and trainings in the same Gantt with 2 different colors.
November 2, 2009 at 11:07 am
Christophe
OK, this should work with the above method. You’ll need to adapt it to reflect your two choices (instead of the three priority choices in the example).
November 4, 2009 at 10:13 pm
MontrealPaul
After days of checking every aspect of my implementation, I finally found why version 1.1 was not working for me. I saw this after scraping the previous version out of the example site.
One rather important part is missing: The code inside of the main tags needs to be defined as a function, like this:
$(function(){
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = "/pics"
etcetera, etcetera
})
(hope my formatting codes stick!)
Thought I’d post here, in the event it might help. It is possible that there’s some other way, that I don’t know of, to implement this, but inserting the ‘funciton’ code made it work for me!
November 4, 2009 at 10:46 pm
montrealpaul
Doh!
Not only were my “< s c r i p t " tags stripped (with good reason – should have thought of that!), but I also forgot the ending "< /code" tag (I've purposely left off the ending brackets here, lest those be stripped as well).
Unfortunately, it doesn't look like I can go back and edit it. Christophe, can you? I've just registered with WordPress, to see if this (and future) posts can be edited/deleted.
November 6, 2009 at 3:06 pm
Christophe
Paul, I think I get your point.
The code is supposed to be placed below the Gantt view and modify it. If you place it above, then you need to delay the execution until the page is loaded (as in your above script). I prefer the former as it happens earlier in the page load process.
December 8, 2009 at 8:08 am
Gantt demos – Update « Path to SharePoint
[...] The second demo shows a method to add color coding to the OOTB Gantt view. The color is based on the level of priority. More details here. [...]
January 11, 2010 at 6:34 pm
Jon
Can this color code be used for a sharepoint calendar with gantt view instead of a project task list?
Also, I would like to have a calendar gantt view for approx 20 individuals in my office but I would like to have only one line per individual and then color code (approx 5 categories) those tasks (i.e. vacation, office, Business trip, etc..). In short I don’t want to have one person with 30 separate lines associated. Thank you.
January 12, 2010 at 4:22 am
Christophe
This solution should work with any SharePoint Gantt view, just make sure you use the correct column names.
With the SharePoint Gantt view, you’ll get one task per line. To get what you want, you’ll need to pull the data from SharePoint and use a custom charting tool. For example FusionCharts free could work for you (scroll down to the Gantt section):
http://www.fusioncharts.com/free/gallery/
January 20, 2010 at 12:26 am
Spyder
So I have the BarImages in the /Picture sub folder of where my Gantt chart is and I have the CEWP with Craig’s script below my gantt WP. When I add Craig’s code the blue bars disappear and I don’t get any bars at all. I’m using the standard status values. I’ve also included the code that is supposed to hide the summary but it doesn’t work either. I’m suspecting that I’m not calling the jquery library properly but I don’t understand why or how to fix it. Any ideas?
January 28, 2010 at 12:47 pm
Christophe
Do you get red crosses instead of colors? If so it means that the path to your images is not correct.
January 28, 2010 at 3:23 pm
Spyder
No red crosses either.
March 24, 2010 at 12:33 pm
dieter
It’s not working for me either. It tries to load the images without the numbers – “CenterNormal.gif” instead of “CenterNormal0.gif”. I havent changed anything else but the column names in the script…
March 24, 2010 at 2:46 pm
David Owens
I have the same problem of not getting this to work. I have a choice of overall project status that can be Red|Yellow|Green. I also have sub-status components for things like scope, stakeholders etc, that can also have values of Red|Yellow|Green. Is the script looking for values in any certain column? will the fact that I have multiple columns returning the same values be a problem etc.
thanks,
Dave
March 26, 2010 at 12:28 pm
magicandri
Correct dieter,
It put red cross but only on the first task in the list.
The image appears as CenterNormal.gif without numbers also if it’s supposed to be CenterNormal2.gif
Thoughts folks?
March 26, 2010 at 1:49 pm
magicandri
SOLVED!
No group…but also…no Total and it will works.
March 28, 2010 at 1:53 pm
Christophe
Thanks magicandri. With this sample code, the script expects to find one task per line in the summary view. Grouping or totals will break it. What you would need to do is add a filter that only selects the tasks.
March 30, 2010 at 4:54 pm
Brent Johnson
When I remove the comment tag from the hide the list style code it does not hide the list below the Gantt Chart. Is anyone else having this problem?
April 7, 2010 at 7:03 pm
Pedro Rodriguez
Solution to red x and color not displaying.
Like many users above i also spent 2 days trying to fix the color not displaying or getting red x. My employee Ann Lu found the problem.
The source code says to replace the path to the jQuery libarary with HTTP://path and to “change the path” to the picture library, i bet that many people assumed you need http for the image library, huh?
For the jQuery path (internal or external) you DO NEED http in the path. However, for PicturesPath use a reference path WITHOUT http. The path for PricturesPath should look like:
“/subsitename/libraryname”
April 8, 2010 at 12:27 am
Christophe
Thanks Pedro.
It seems that different people actually had different issues with this script. I’ll add more details to the post based on your comments.
April 8, 2010 at 4:11 pm
Pedro Rodriguez
no, thank you Christophe, you just started a Sharepoint revolution by implementing a feature that should have been standard part of Sharepoint. You are the MAN!
April 16, 2010 at 12:37 pm
Jonas Eifrém
Here you have the code for two colours on every gantt row.
In this case we have a vacation and in that vacation there is two dates where the row is suppose to be in a different colour.
The two new dates are taken from the list under the gantt view.
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/GanttImages”;
// Collect the priority level for each task
var barColours = new Array();
var jourColours = new Array();
var regex = /\(\d\)\s(Ledig|Semester|Jour)/;
// Find the tasks summary list
var TasksList = $(“.ms-ganttOuterTable”).siblings(“table”).find(“.ms-summarystandardbody>tbody>tr:not(.ms-viewheadertr)”);
if (TasksList.length == 0) TasksList = $(“.ms-ganttOuterTable”).siblings(“table”).find(“.ms-listviewtable>tbody>tr:not(.ms-viewheadertr)”);
TasksList.each(function(i){
try {
barColours[i] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err) {barColours[i] =”";};
try {
var vacationStartDate = $.datepicker.parseDate(“yy-mm-dd”, $(this).find(“td:nth-child(4)”).text());
var vacationEndDate = $.datepicker.parseDate(“yy-mm-dd”, $(this).find(“td:nth-child(5)”).text());
var jourStartDate = $.datepicker.parseDate(“yy-mm-dd”, $(this).find(“td:nth-child(6)”).text());
var jourEndDate = $.datepicker.parseDate(“yy-mm-dd”, $(this).find(“td:nth-child(7)”).text());
var day = 1000 * 60 * 60 * 24;
var jourStartIndex = jourStartDate.getTime() – vacationStartDate.getTime();
var jourEndIndex = jourEndDate.getTime() – vacationStartDate.getTime();
jourStartIndex = Math.ceil(jourStartIndex / day);
jourEndIndex = Math.ceil(jourEndIndex / day);
jourColours[i] = { start: jourStartIndex , end: jourEndIndex };
}
catch(err) {
};
});
// Modify the bar color according to priority
$(“.ms-ganttTaskRow”).each(function(i){
$(this).find(“img”).each(function(j){
var jourInfo = jourColours[i];
var source=this.src;
if (jourInfo != undefined &&
jourInfo.start != undefined &&
jourInfo.end != undefined &&
j >= jourInfo.start &&
j <= jourInfo.end ) {
source = source.replace(/.gif/, "3.gif");
} else {
source = source.replace(/.gif/, barColours[i]+".gif");
};
source = source.replace(/\/_layouts\/images/,PicturesPath);
this.src=source;
});
});
//Optional: hide the list under the Gantt view
$(".ms-summarystandardbody").hide();
April 27, 2010 at 4:31 pm
Anthony Perry
I try to implement this on my site as per the instruction on the summary view, its only displaying standard images CentreNormal.gif! what am I doing wrong here?
May 7, 2010 at 8:44 am
Jonas Eifrém
My code was just a proof of concept for multiple colours. It needs some more explanation of how it works though before you can just “use it”.
To start with the code picks the dates from a specific place in the list. So the order and placement of the columns have to be a exact match or you just change in the code.
May 7, 2010 at 8:49 am
Jonas Eifrém
If you have any questions you are always welcome to contact me by mail at jonas.eifrem [at] sweco.se
April 28, 2010 at 3:22 am
Anonymous
Hi,
I thought I had everything in place, checked your source code, but still have red Xs. When I check the properties, the path leads to the proper folder for the color files, but it is searching for the standard “StartNormal.gif”. The column I need is in the gantt view and I have have tired the priorities with just straight names and with the numbering shown above.
What could I be missing?
Thanks,
Carolyn
April 28, 2010 at 1:34 pm
Anonymous
Nevermind…. I kept messing with it and got it to work
Good stuff here – Thanks!
April 28, 2010 at 1:52 pm
Carolyn
Hi,
What was used to genereate the GIFs? Is there a place where i can get some more already made up so that I do have to try to match?
Thanks,
Carolyn
April 28, 2010 at 10:51 pm
Robbie
Hi, we try to use this with 2 different colors. But it seems that the script always check for three. The first color he don’t find (no number at the end of the file) then come color xxx1.gif, xxx2.gif and after this he starts again with xxx.gif – which don’t exist. any idea?
June 28, 2010 at 4:45 pm
RobH
Has anyone figured out the issue where the red x shows up because it is looking for ‘StartNormal.gif’ instead of ‘StartNormal1.gif’, ‘StartNormal2.gif’, etcetera?
If finds them just fine if I copy and change the name to remove the number, but then the script doesn’t work like it is supposed to.
Any help?
Thanks.
July 30, 2010 at 1:16 pm
Domenico
Hello,
I have been trying this for few days now but without any success. Can anyone assist please? My issue is that I see red crosses and when I right click and look in properties I see that it doesn’t point to the image patch (http://sharepointemea/Pictures/EndNormal.gif). Also the image names are not numered asRobH pointed out previously. I explain exactly what I have done. I paste here below the code that I am using so that you can tell me if there is something wrong. Should I replace the “/Pictures” after var PicturesPath with anything?
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/Pictures”;
// Collect the priority level for each task
var barColours = new Array();
var regex = /\(\d\)\s(High|Normal|Low)/;
// Find the tasks summary list
var TasksList = $(“.ms-ganttOuterTable”).siblings(“table”).find(“.ms-summarystandardbody>tbody>tr:not(.ms-viewheadertr)”);
if (TasksList.length == 0) TasksList = $(“.ms-ganttOuterTable”).siblings(“table”).find(“.ms-listviewtable>tbody>tr:not(.ms-viewheadertr)”);
TasksList.each(function(i){
try {
barColours[i] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err) {barColours[i] =”";}
});
// Modify the bar color according to priority
$(“.ms-ganttTaskRow”).each(function(i){
$(this).find(“img”).each(function(){
var source=this.src;
source = source.replace(/.gif/, barColours[i]+”.gif”);
source = source.replace(/\/_layouts\/images/,http://sharepointemea/sites/sharepointtest5/BarImages);
this.src=source;
});
});
//Optional: hide the list under the Gantt view
//$(“.ms-summarystandardbody”).hide();
Thanks you in advance for your help
Domenico
August 3, 2010 at 10:12 am
Domenico
Can anyone help me please?
Domenico
August 3, 2010 at 2:11 pm
Christophe
Domenico, where in your SharePoint site did you upload the images?
August 4, 2010 at 7:46 am
Domenico
Hi Christophe,
Thanks for your reply,
I have created a forlder called BarImages under Document Libraries and I have uploaded the images there. The address would be http://sharepointemea/sites/sharepointtest5/BarImages/Forms/AllItems.aspx or http://sharepointemea/sites/sharepointtest5/BarImages
August 2, 2010 at 3:05 pm
David
Has anyone tried using this with the Easy Tabs web part? I have multiple projects that I am displaying using Easy Tabs, but when I include this code in the CEWP, I lose my graph for all but the first project. The first tab shows up great, but when I look at the other projects I get the red X. After looking at the source for these images, it doesn’t quite complete the source. For the first tab, when I right click it shows a source of “/projects/Shared%20Documents/StartStatused3.gif”, on the second tab it shows “/projects/Shared%20Documents//StartNormalundefined.gif” Has anyone run into this problem?
August 2, 2010 at 3:21 pm
Christophe
David, two questions:
- are all your project views rendered correctly on the page if you remove the Easy Tabs?
- which version of the Easy Tabs are you using? I’d recommend to do your tests with v5 which was released in July.
August 3, 2010 at 7:37 pm
David
I was using version 4 of easy tabs, but even when I removed easy tabs it wasn’t rendering correctly. The entire first graph was fine, the second graph showed 3 of 4 lines correctly, and the third graph was all red x’s. In the second and third graphs where I was receiving an error, it was still showing “undefined.gif” at the end of the location for the red x’s.
August 4, 2010 at 1:41 am
Christophe
Right, the issue is not with the Easy Tabs. The script is written to grab the first Gantt view on the page, you’ll need to adapt it if you have more than one.
August 6, 2010 at 6:47 am
Domenico
Can anyone help me to solve my issue?
Thanks in advance
August 10, 2010 at 4:52 am
Christophe
Domenico, you have to set PicturesPath in the code to reflect the actual location of your images (read the comments in the code).
August 10, 2010 at 1:01 pm
Domenico
Hi Christophe,
Thanks for your replay,
I have tried everything, I think that I took all the correct steps but it doesn’t work.
- I have set the PicturesPatch to point the place where I have stored the images ( source = source.replace(/\/_layouts\/images/,http://sharepointemea/sites/sharepointtest5/BarImages)
-I have put the web part below the Gantt chart
-When I right click on the the bar I see that it still looking for the standard standard “StartNormal.gif”
- Also I don’t have Red X I have the normal view
Please help
Thanks in advance
August 12, 2010 at 8:02 am
Domenico
I am keeping messing with the code. My issue is that the code is not looking for CentreNormal0,CentreNormal1 etc instead is looking for “StartNormal.gif”
August 14, 2010 at 4:08 am
Christophe
Domenico, is the Priority field displayed in your list? The script needs it to assign the correct image.
If you need personal assistance, feel free to subscribe to a one-on-one session on my home page.