SharePoint 2010 Pie Chart with Counts
So you want to use an out of the box (OOB) SharePoint pie chart to tell you how many list items have a certain status (or other column choice)? Trying to add that web part to a page and setting its target list as the list you want will not work. Many 3rd party tools exist to deal with this exact limitation of the OOB charting web part. The good news is that in SharePoint 2010 there is an easy way to get this data graphed with the OOB pie chart using a little known trick. For this example I will show you how to set up a Task list where you want to show the Status field count values in a pie chart.
Step 1, create a custom list called StatusLookUp and add an item for each status you want to have. The items in the list will be used as statuses in the “Status” column via a lookup column.
Step 2, create the list you want to use to track your tasks, for this example I am calling it ProjectStatus. If you already have a list this will work as well, you will need to migrate your status column data though. After you have your list setup, create a column called StatusLookup. It will be a Lookup column type and you will use the StatusLookUp list as your input. After creating this column you will need to migrate your current Status column data to this column if you already have a list, if not create a few test items and set their status using this column. This will be a small burden to migrate the statuses of each item but well worth it. I recommend doing it programatically via .Net as a console app or ASPX page. The code for that will simply loop through your list and set the new column data as the current column data with the exception that you will need to format that data to fit into a lookup field type.
This is my basic list with 4 projects that I am tracking and what the status is of each. Note that the StatusLookup field is a lookup of the StatusLookUp list and not the OOB Status field.
Step 3, create a new Lookup column in your StatusLookup list. Call the column Count and reference the column that you just created in your ProjectStatus list. Be sure the column contains “(Count Related)” in the name. Now that you have created your new Status field in your list and migrated the data over, go back to your original StatusLookup list and create a new column that is a lookup of the column that you just created as a lookup to this list. It sounds like a crazy loop but when you do this it returns a count of the number of occurrences instead of the same data.
Step 4, add the chart web part to the page and connect it to your Status Lookup list. Set the Count as your Y axis and the Title as your X axis. Finally, customize your chart to be a pie graph and set your data to display as you wish. Viola! Since this post is about the data and not really about the pie chart I skimmed this part but trust me, you can totally just add the web part and walk through the setup wizard and get the data you need.
Hope this helps, enjoy.
Dead Aid: Why Aid Is Not Working for Africa
I decided to read this book because it sounded interesting, political, and topical; and it definitely was. This eye-opening book details the unbelievable history of aid and Africa. Until you read this, you have no idea how bad it really is. To top it off, Dambisa Moyo meticulously shows how aid is actually causing African nations to regress and subsequently allowing China to slowly permeate the continent.
This is a fascinating read and I recommend this book, however be aware that it is very detailed and can seem almost academic at times.
Closing Time, the Long Awaited Review
If Catch-22 is your all time favorite book like me, then you must stop everything and read Closing Time immediately. This is one of the best sequels ever written and it took me by surprise right from the start.
We last saw Yossarian running out the door during the war, but this book waits decades to catch back up with our favorite character. Now in his 70s, Yossarian has lived an interesting life but still maintains his penchant for hospital nurses. His world these days is vastly different from the first book but it is filled with numerous characters, old and new. Milo and the Chaplain have had interesting lives as well as have ancillary characters from the first book, and the book is an eclectic mix of all their stories.
Towards the end, the book becomes harder to follow and characters begin passing away but once you finish it and reflect, you are left with a wonderful book and story. I could not recommend this book higher if you have already read Catch-22.
SharePoint 2010 Hide Left Navigation
If you Google search the title of this blog post you will find numerous sites that tell you how to easily accomplish this via a simple CSS style change. Use a hidden content editor web part, just like my last post (except you don’t need jQuery), and add the following code:
<style>
BODY #s4-leftpanel { DISPLAY: none }
.s4-ca {MARGIN-LEFT: 0px }
</style>
Done. Simple. However, what if you want the ability to show and hide that on demand? Then you will need this handy JavaScript script code. Just like before, add a content editor web part to the page but this time don’t hide it. Add the following code and you will be able to show and hide the left navigation on demand:
<script language=”javascript”>
function toggle() {
var ele = document.getElementById(“s4-leftpanel”);
var s4 = document.getElementById(“MSO_ContentTable”);
var text = document.getElementById(“displayText”);
if(ele.style.display == “block”) {
ele.style.display = “none”;
s4.style.marginLeft = “0px”;
text.innerHTML = “show”;
}
else {
ele.style.display = “block”;
s4.style.marginLeft = “155px”;
text.innerHTML = “hide”;
}
}
</script>
<a id=”displayText” href=”javascript:toggle();”>Show</a> <== Click Here
Now you have two easy options for temporarily or permanently hiding the left navigation in SharePoint 2010.
There are a number of enhancements to this code that can be made to make it even more useful. The first is the bug that requires 2 clicks to get it working and the second would be setting the user’s selected preference in a cookie so that it always remembers the state that it was in the last time the user logged in. I may work on these in the future but feel free to post that code in the comments section or contact me directly and I will post an update or link to your blog!
SharePoint 2010 Access Denied Web Part Error
After upgrading to SharePoint 2010 some web part pages are showing an Error “Web Part Error: Access denied. You do not have permission to perform this action or access this resource.“. For sites without anonymous access, this can be mitigated with audience targeting of the web part. However, if that does not work or you need to have the page be anonymously accessible, but also have web parts on that page that have limited permissions, then you will need a different solution. This is not the perfect solution you are looking for, I am still waiting on Microsoft for that as well, but this is a simple jQuery trick that will hide that awful error and make the page render as you would expect (MOSS 2007 functionality). Just follow the following steps:
- Download the latest version of jQuery from their site: http://jquery.com/ and upload it to your server.
- At the bottom of the page add a content editor web part and make it hidden.
- Add the following code:
<script src=”your-server/jquery-1.6.1.min.js”></script>
<script language=”javascript”>
$(“span:contains(‘Error’)”).hide();
$(“div:contains(‘Access denied’):not(:has(div))”).hide();
</script>
The first line is a reference to the latest version of jQuery on your server. Please remove “your-server” and replace with the correct folder (don’t use absolute references). Make sure this reference works. (It is also possible to link to a Google hosted version of this file however I always use a local copy.) The second line is the beginning tag for writing JavaScript. The 3rd line finds all the “span” elements on the page that contain the word “Error” and then hides them. This might work too well so you need to make sure nothing else on the page is hidden as well that you don’t want hidden. The fourth line finds all the “div” elements that contain “Access denied”, but do not contain any other “div” elements, and hides them. This is crucial as I was unable to hide a “span” and had to use a “div” find and hide. However, since “div” tags are nested throughout this page without the caveat that makes sure the “div” tag doesn’t contain any nested “div” tags, this would have hidden most of the items on the page. The fifth line closes the script tag.
Don’t Bother Reading Linchpin
I made it through 108 pages of this worthless, psychobabble garbage before giving up and returning the book to the library. Let me save you the time and summarize the book for you: “Working hard isn’t enough, create emotional relationships, the world has changed, linchpins are what’s needed, your lizard brain will tell you otherwise, rinse, repeat”. After reading this, I now wonder how Seth Godin is held in such high esteem. The entire book could (should) have been a Gen-Y centric blog post but instead it is drawn out over a few hundred pages of bullshit rhetoric. Here’s my advice: don’t read the book, do more than what is asked of you at work, be personable, be important but not indispensable. Counter to what Mr. Godin says, linchpins don’t get promoted because they are too important where they are at and no boss wants to lose that.
The Girl Who Played With Fire…
is the amazing sequel to The Girl With The Dragon Tattoo! After a year or so break, our favorite protagonists are back at it with a mystery from Lisbeth’s dark past. It twists and turns and exposes more about her than she would want you to know. The climax at the end of the book leaves you hanging as to our heroines fate, but luckily the third book (of the Millennium Series) picks up immediately after this one ends. Another 10 out of 10 for Stieg Larsson.
Review of Starbucked by Taylor Clark
“A Double Tall Tale of Caffeine, Commerce, and Culture” just about sums up this book. Starbucked is a short read that is pretty entertaining if you like coffee or business or culture and just want the 30,000 foot view with some interesting and entertaining stories. The history and astounding growth of Starbucks is quite interesting, as are the stories about the history of coffee and the culture surrounding all of them. I recommend this as a quick read but not as highly as some of the previous books I have just reviewed.












