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”).
[09/15/2010: link updated to the new Toolkit location]
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!
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.
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)/;
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.
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
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!
Nevermind i got it working i think this was a translate error since im using the project site in dutch.
At last! Someone with the insight to solve the prlebom!
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?
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.
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?
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.
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.
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;
});
});
});
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.
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)/;
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.
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!
I also found out that the script will not work if you use the gantt within a web part.
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…
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.
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!
You and Craig are wonderful!! thank you and I will stay tuned to this 🙂
kaboilek, send me an e-mail: crlowrieATgmailDOTcom and I’ll see if I can help sort out your code issues.
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
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?
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.
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).
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!
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.
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.
Pingback: Gantt demos – Update « Path to SharePoint
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.
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/
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?
Do you get red crosses instead of colors? If so it means that the path to your images is not correct.
No red crosses either.
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…
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
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?
SOLVED!
No group…but also…no Total and it will works.
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.
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?
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”
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.
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!
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();
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?
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.
If you have any questions you are always welcome to contact me by mail at jonas.eifrem [at] sweco.se
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
Nevermind…. I kept messing with it and got it to work 🙂 Good stuff here – Thanks!
What did you do? I eliminted all groupings, filters, from the view…used relative and absolute paths to the var PicturesPath…use this on the Priorities column, set the attributes with the “(1) High” and just “High”….Can’t get the blooming thing to work! Would give up if it wasn’t so useful to my project! Please help!
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
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?
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.
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
Can anyone help me please?
Domenico
Domenico, where in your SharePoint site did you upload the images?
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
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?
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.
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.
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.
Can anyone help me to solve my issue?
Thanks in advance
Domenico, you have to set PicturesPath in the code to reflect the actual location of your images (read the comments in the code).
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
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”
DOmenico
Are you using subtotal or any other type the data filter? if yes ..remove them?
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.
I want to download the script and the images but for some reason unable to get to them. Are they still there?
i can’t get to your download or demo pages. i get this error:
Cannot connect to the configuration database.
I’ve had issues with the site in the past few weeks, sorry about that. The files are now available in another location, and I have updated the link in the post accordingly.
Christophe,
Is there any way to put this in CSS/HTML instead of javascript? I am on an intranet and my company has .js files and javascript coding disallowed.
cannot connect to the configuration database when trying to connect to the download site,
Help please the url I’m using is http://www.pathtosharepoint.com
Michael, see my latest post for the valid URLs.
I’m having the same issues as others, script doesn’t seem to locate the images. Also I downloaded the script on September 17th. Is the path still correct?
What happens? Are you seeing red crosses? If so, right click on them and view their properties. It will tell you where the script is trying to pull the images from.
Hello, is this available for SharePoint 2010?
Jack, currently I don’t have a solution for SP 2010. Actually, I looked into it this week. The 2010 version uses graphics and works differently in different browsers, so it makes things more complicated.
Hi,
I’m having the same issues a lot of other people seem to have (numbers are missing, i.e. “CenterNormal.gif”). I think I have made all reasonable changes that are suggested in the comments but it still doesn’t work. It’s a pity that René hasnt elaborated on his solution.
I’ve uploaded a screenshot of my gantt-view:
http://www.flickr.com/photos/orange8interactive/5122476817/
The CEWP2 contains the following script:
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/sites/ipm/marketing/productmanagement/team/Tools/Farben für Massnahmenplan/BarImages”;
// Collect the priority level for each task
var barColours = new Array();
var regex = /\(\d\)\s(Nicht\sbegonnen|In\sBearbeitung|Abgeschlossen|Zurückgestellt|Neu\sdefiniert)/;
// 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/,PicturesPath);
this.src=source;
});
});
//Optional: hide the list under the Gantt view
//$(“.ms-summarystandardbody”).hide();
The red crossed images have the following property:

Does anyone have a clue what’s wrong?
Thanks a lot for your help.
Eddy
okay, I have made it work:
source = source.replace(/.gif/, barColours[i]+”.gif”);
had to be changed to
source = source.replace(/.gif/, barColours[i]+[i]+”.gif”);
sorry, this is not the solution.
And finally, the real solution:
I didn’t know, that you had to number your choice list like this:
(1) choice1
(2) choice2
(3) choice3
now it works perfectly with the initial code.
Eddy, good to hear you got it to work. Right, the code was built for the default Priority column, which has numbered items.
I was able to get the colors working, but my slider no longer functions. Is anyone else having this issue?
Can’t get the colors to work as the basic sample provided. Thinking my PicturePath URL is incorrect. What part do I grab to place in the CEWP source editor?
Pictures loaded in shared documents
For those interested, I am starting a new series of online workshops, including one on the Gantt view. For details and updates, please visit my home page:
http://sp2010.pathtosharepoint.com
Hi Christophe, many thanks for providing the script and clear instruction. Although I am completely new with sharepoint and has no clue about javascript, it only took me only few minutes to implement. I used the option of pasting your code in the source editor of a Content Editor Web Part. I first placed Content Editor Web Part at the top of the page (position 0). which did not work. Then I moved web part to the bottom of the page, which works. Juuhuuuu!
Thanks again and wish you a very happy new year.
Bing
Hi Christophe, I managed to get this working with my own criteria, but I don’t see anywhere how to make it mark the bars in the two tones for % complete, what am I missing?
Thanks
Chris
Ignore me Christophe, I just marked my task as 50% complete and it is now showing the % complete so I guess a 3 day task will only show increments in 33%, a 4 day task in increments of 25% etc.
Right, the unit for the Gantt view is a day (rendered as a table cell with a picture).
I have tried for days to get the script to work, There is no reason it should not work.
Every step followed yet I get eather the default images in layouts or red x’s.
I can access the images directly in the browser as well so pathing is correct.
Path in the script is set to the actual path not the http.
I am about to give up on this any help would be great?
Here is my code its the same as the downloaded one.
I only changed script path and images path, no matter what avriation it’s either red x or default images.
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/ganttbars”;
// 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]+[i]+”.gif”);
source = source.replace(/\/_layouts\/images/,PicturesPath);
this.src=source;
});
});
//Optional: hide the list under the Gantt view
//$(“.ms-summarystandardbody”).hide();
I did notice the numbers when it was a red x was not displayed in the image properties. any clues would be helpful.
May sound silly but you must have a column shoing the numbers and data visible.
e.g (1) High etc.
I am currently having issues with getting my gantt view (created off of a custom list) to stay within the page margins, much less the web part width. It looks like your Gantt is working properly. Is there anything you can suggest to get this to work as expected?
Thanks!
If you are using Internet Explorer, the Gantt should auto-adjust, I don’t know why you’re having this issue. If you are using another browser like Firefox, then SharePoint will display the Gantt in full width.
I’ve got the color-coding to work but when I add another CEWP and add the code to rescale the gantt with the slider bar it breaks. Any helpful tips here? I have the slider CEWP before the task list and the color-coding dwp after the task list, and before I added the code to create the slider-bar, it was working fine.
hi christophe – great script but i really need the color coding to work with grouping and filtering wont do. any suggestions? thank you
For this to work, the script needs to find the color. If the color is not displayed because of the grouping, you’ll need another way to get it (like a Web service call), but it becomes more complicated.
Have you considered this other option:
https://blog.pathtosharepoint.com/2008/10/29/gantt-view-first-test/
Hi, I was able to get the colors to work after playing with script and the web parts for a few hours yesterday. (Thanks, by the way. This is really cool!)
I’m trying to hide the list under the gantt view, but haven’t been successful yet. Any suggestions on what to check first? Thanks in advance.
Melanie try this, if Gantt shrinks somehow, just add with and height
.ms-listviewtable{Display: none;}
I have modified the script to work for statuses, and other fields (without needing a numeric prefix in brackets).
Code is below:
var PicturesPath = “/testsite/Scripts/BarImages”;
// Collect the Status level of each task
var barColours = new Array();
var regex = /(Not\sStarted|In\sProgress|Completed)/;
// 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)
{
//1 for Not Started
//2 for In Progress
//3 for Completed
try
{
var currentItem = regex.exec($(this).text())[0];
var index;
if (currentItem == “Not Started”)
{
index = 1;
}
else if (currentItem == “In Progress”)
{
index = 2;
}
else if (currentItem == “Completed”)
{
index = 3;
}
barColours[i] = index;
}
catch(err) {barColours[i] =”0″;}
});
// 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;
});
});
Adam, thanks for sharing!
Did anyone happen to notices that the word “colors” is spelled “colours”? My images weren’t showing and when I changed “colours” to “colors” the images displayed with no problem.
I tried to modify this even further (thanks, Craig & Adam!) to color the Gantt based on custom fields, however, it didn’t work
I was able to get the code based on Priority to work, but not this one OR Adam’s based on Status. Any ideas? below is the code:
(Note, I created a new column named “Activity” which is used to characterize the type of Task. These are “Scope”, “Analysis”, “Budget”, “Planning”, & “Proposal”. To coincide with the extra task I created a 5th color option, also placed in library. I called the library “Image Library”).
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/site/Image%20Library”;
// Collect the activity type for each task
var barColours = new Array();
var regex = /(Scope|Analysis|Budget|Planning|Proposal)/; //Milestone
// 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){
// 0 for Scope
// 1 for Analysis
// 2 for Budget
// 3 for Planning
// 4 for Proposal
try
{
var currentItem = regex.exec($(this).text())[0];
var index;
if (currentItem == “Scope”)
{
index = 0;
}
else if (currentItem == “Analysis”)
{
index = 1;
}
else if (currentItem == “Budget”)
{
index = 2;
}
else if (currentItem == “Planning”)
{
index = 3;
}
else if (currentItem == “Proposal”)
{
index = 4;
}
barColours[i] = index;
}
catch(err) {barColours[i] =0;}
});
// Modify the bar color according to activity
$(“.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;
});
});
btw, happy to share the extra colors if anyone is interested (purple & brown)
Would be interested in the extra colors! Can you send or post a link?
Hi James, Would love the extra colors – please mail to trilloa@gmail.com many Thanks! regards Aaron
I would love to have more colors. russell.brooks@sprint.com
I would love the extra colors
Thanks guys, it took some playing around with but it works quite well. Just a quick question though. One of the last lines of code suggest an optional line that can hide the list that always accompanies the gantt chart (below it). When I un-comment this code, I notice no difference.
My old method of hiding this list did not include coding, I simply “grouped” all of the list items by an item that they all have in common. However, upon reading this thread, I realized that the grouping was preventing the colour code from working in the first place.
Any suggestions as to how I can hide this list below the gantt chart? Oh, for context, the Gantt chart is within a webpart on a page with many webparts, and the code is in a CEWP.
Hey all. For some reason the first item on the gantt task lists is still displaying a red X box, while the rest of them are all working perfectly. The first item is searching for the original milestone image for some reason, (which it of course can’t find).
Has anyone run into this problem/know how to fix it? I have a feeling it may be as simple as a counter error, but I’m not sure.
-Zach
Do you have it counting anything? I had it counting how many items were in the list and it did the same for me. Just remove any counters that you have on the list and it should work.
Also, grouping. Anything that adds a line to the tasks list.
If you change the “Find the tasks summary list” piece to the following, it should fix your grouping/header problems:
// 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)”).not(“.ms-gb”);
var j = 0;
TasksList.each(function(i)
{
try
{
barColours[j++] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err) {
j–;
//barColours[i] =””;
}
});
Thank you so much for your help guys. I actually found out what the issue was, and it was much simpler than I had thought, but I thought I’d let you guys know either way.
The issue was that I was grouping the items in the list based on their “Activity” which is a yes/no choice, but all of the items are yes anyway, so there is only one row added. As such, getting the colours to work properly (and not skipping a line, as it turned out whas happening) simply took setting the counter one step back in it’s progression from the start.
TasksList.each(function(i){
try {
barColours[i-1] = regex.exec($(this).text())[0].substr(1,1); // i-1, instead of i
}
catch(err) {barColours[i] =””;}
});
Anyway, it was as simple as that for me. Thanks again for all the help!
-Zach
Hi – does this work with sharepoint 2010?
Hi Guys, Below is my code for changing colours for my status’s and in the code the various status (Not Started But Approved, Not Started Waiting On Approval, In Progress, Completed, Cancelled, On Hold) I cant get it to add a number to the gif file to change the image it uses.
Also, does anyone have more colors they can send? My email is trilloa@gmail.com.
I Appreciate any help anyone can provide to get this to work – its an awesome idea and I am surprised its not standard.
The column is called Task Status.
Regards
Aaron
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/communities/nzisssdmcop/PublishingImages”;
// Collect the Task Status level for each task
var barColours = new Array();
var regex = /\(\d\)\s(Not Started But Approved|Not Started Waiting On Approval|In Progress|Completed|On Hold|Cancelled)/;
// 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+1] =””;}
});
//TasksList.each(function(i){
//try {
//barColours[i-1] = regex.exec($(this).text())[0].substr(1,1); // i-//1, instead of i
//}
//catch(err) {barColours[i] =””;}
//});
// Modify the bar color according to Task Status
$(“.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;
});
});
//Optional: hide the list under the Gantt view
//$(“.ms-summarystandardbody”).hide();
THis work great for SharePOint 2007, however, it doesn’t work for SharePoint 2010. Is there solution to 2010 ?
Thanks,
M
The 2010 Gantt is completely different from the 2007 one. I have done some color coding tests, but I have not published anything (and I haven’t seen anything on other blogs either).
Kristina, Are you saying if I paste “// 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)”).not(“.ms-gb”);
var j = 0;
TasksList.each(function(i)
{
try
{
barColours[j++] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err) {
j–;
//barColours[i] =””;
}
});
” into the original code, it will allow me to use the color coding on my gantt chart even with grouping and filtering applied?
Got it working with a normal ‘Task List’ but was trying to initially get it to work with a ‘Calendar List’.
So, my question is this. How could you modify, make this code work with a ‘Calendar List’ displayed as a Gantt as opposed to just strictly a ‘Task List’ as a Gantt View. I am assuming some tweaks would be needed in this code here, but I am not sure where to begin. Any advice greatly appreciated.
// 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)”);
Would need to reference the SharPoint Calendar types?
FYI, I came up with a pretty neat solution here to change the current day color marker in the Gantt view from the invisible ‘cornsilk’ yellow to something more visible. Thought I would pass this along as my thanks for sharing your great Gantt view knowledge here to others.
http://social.msdn.microsoft.com/Forums/en/sharepointcustomization/thread/54743cb4-226c-41e9-99e8-9dc62aca1084
Oh yeah, any reply to my previous comment above on how to get the colors to work on the Calendar View Gantt. I am still struggling with that one. =(
I found what was causing the red crosses (instaid of the images) in my project. I was testing this on a “Dutch” site. This code uses English parameters so this will only work on an English site. It took me some time to figure this out.
Hi Chris
This is really good. It helped my Proj Management site to really stand out.
However, I just encountered an issue that I’m not being able to overcome.
Some of the tasks are appearing with red crosses. It is only some of the tasks, and it is independent of the RAG (i.e. (1) Green works for some and not for others), I don’t have any filtering or groupings.
Do you have any idea of what might be the issue?
Any assistance would be greatly appreciated.
I followed your blog on Color Coded Gantt View, but can’t get it to load with the colored bars- I still get the blue bars.
I think my problem is with the jquery path and possibly with the library where the images are stored.
I have a site where I have:
1- Task list with Gantt View (where I want my color coded Gantt)- I do not have any grouping or special features. I do have the priority in the view below.
2- I have a picture library within this site called ‘CustomizeGanttBar’ where I have the images stored.
Here is the beginning of my script in the CEWP (the CEWP is located below the ‘Tasks’ WP).
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/AlbemarleMassSheltering/CustomizeGanttBar”;
Here is the beginning of my script (didn’t seem to post in previous post)
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/AlbemarleMassSheltering/CustomizeGanttBar”;
Clearly it takes out my script…
so the jquery path I use inside the appropriate scrip tags:
https://myURL.net/ProjWorkSpace/AlbemarleMassSheltering/CustomizeGanttBar/Forms/AllItems.aspx”
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/AlbemarleMassSheltering/CustomizeGanttBar”;
Can’t get this to work…. played with it for a few hours now.
The bars are all still blue.
Added the script to a content editor web part above my gantt view, changed the path (“/Picture Library”), and tried a few different possibilities…
Can you have a space in the path, or do you need to have %20? – tried both ways, but still want to know
I have site owner permissions, but my site is a subsite of a massive group of sharepoint sites, is it possible there are permission issues?
At one point i even tried to force barColours[i] = 2; but the bars were still blue.
got this to work in 2007, then the site migrated to 2010….Need this to work in SP 2010… Has anyone been able to do this?
Here is some java script I gathered along the way. I cannot remember where I found it anymore, but I was able to acheive color representation of the completion leve of the tasks with the task bar turning green upon 100% completion. Overdue task bars were red and % complete showed yellow. Current tasks were blue with green showing the % complete. I had a library of gifs and modified the names to choose the colors I wanted. We also pemanently hid the task listing that was below the chart and extended the title area cells to give more room for title length. I would like to include a screen shot, but I am not sure how to do that here.
$(document).ready(function(){
// Begin New section
// Set PicturesPath to the URL of the library that hosts the bar images:
var PicturesPath = “/sites/PAI/PAIO PIX/”;
// 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-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(0,0);
}
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/, “/sites/PAI/PAIO PIX/”);
this.src=source;
//Optional: hide the list under the Gantt view
//$(“.ms-summarystandardbody”).hide();
// End NEw section
});
});
var currentdate = new Date();
$(“.ms-ganttTaskRow”).each(function(i){
//Get the task due date
var d = new Date(this.attributes(“originalTaskFinishDate”).value);
//if due date has value
if(d.getYear() !=1)
{
var datediff = Math.round((currentdate – d) / (24 * 60 * 60 * 1000));
//if due date is greater than current date
if (datediff > 0 ){
var source=this.innerHTML;
//check if the task is completed
var match = /(Normal.gif)|(MileStone.gif)/.test(source)
if(match)
{
$(this).find(“img”).each(function()
{
var source1=this.src;
//replace blue with red
source1 = source1.replace(/.gif/, “Red.gif”);
//change the path of image to where the red images are stored
source1 = source1.replace(/\/_layouts\/images/, “/sites/PAI/PAIO PIX/”);
this.src=source1;
});
}
}
}
});
});
.ms-navframe{ display:none; }
.ms-titlearealeft{
display:none;
}
.ms-leftareacell{ display:none; }
.ms-pagetitlearea{ display:none; }
.ms-titlearearight{ display:none; }
body {background-color:#83B0EC}
.ms-main {}
.ms-globalTitleArea {background-color:#fffFFF}
.ms-bodyareapagemargin {border-top:1px solid #83B0EC}
.ms-bodyareaframe {background:none transparent}
.ms-ganttInnerTable {background-color:#fffFFF}
.ms-bodyareacell {background-color:#C9F5D1}
.ms-ganttdiv {height:100%}
.ms-ganttoutertable {height:1000px}
.ms-listviewtable { display:none; }
.ms-ganttTitleHeaderCell { display:100%; width:350px }
.ms-ganttTitleCellText { display:100%; width:350px }
Hi, I got the original script working once I got to understand how the regular expression was workng and the line:
barColours[i] = regex.exec($(this).text())[0].substr(1,1);
is doing.
I still had an error where the first item in the list was broken, while all the remaining items where the colour of the item above it.
I have a fix which puts things right, but I’m concenred that I may cause an index error:
TasksList.each(function(i){
try {
barColours[i-1] = regex.exec($(this).text())[0].substr(1,1);
}
catch(err){ barColours[i-1] =”0″}
});
Can someone explain if my fix is bad mojo, and what I should do to make it right?
Hi Champs,
I am new to SharePoint (SP). I am using SP 2007.
What I want to achieve is creating a gantt view for the team to have a visibility of who will be on leave during Xmas (for example).
It works well if a user has only one entry. But my issues is that whenever a user enters more than one entry for his leave, the gantt view shows it as a separate line/entry. And what I want to achieve is to group it and show all multiple entry as a single time line for that particular user in my view.
For example, person x is away on day1, day 5, day10-day15 and so on. And I want to view it as a single timeline on my gantt view.
I think there must be a out-of-box way to do the same. How can I do that?
Any help will be much appreciated.
Thanks in advance.
Charmis
Hi Charmis, I’d love to have something similar to this but It’s not going to work with the Gantt view as each item only has one start and end date. I was working on a HTML solution that allows multiple events for each per person. Have a look at HTML calculated columns to give you the background
Agree, modifying the Gantt view would require too much effort and it’s better to start from scratch. Search the Web for “timeline” (rather than Gantt) to find such solutions.
An alternate approach would be to use a calendar (color coded by person name).
Using the HTML Calculated Column? I’d love to see the result!
Hello! Did somebody found a solution for SP2010?
Thanks in Advance for your ideas!
The Gantt view in SP2010 is completely different to SP2007. I think its a “start from scratch” proposition.
Right. In SP 2010 the Gantt uses graphics (vml/svg), not standard html tags anymore.
Christophe If You could help for this 2010 thing…i am stucked!!