Paul's Programming Notes     Archive     Feed     Github

SPJS Charts - Dynamically Select Filter Item

I've been using SPJS charts to make google charts with data from sharepoint lists. If you use a custom drop-down filter, you may want to dynamically select items in the drop-down like I did.

An example: You're using a drop-filter which filters the results by week, but you always want it to select last week.

Snippet:


function manualLoad(){
loadManually = false;
spjs_GenerateChart();

Date.prototype.getWeek = function() {
     var onejan = new Date(this.getFullYear(),0,1);
     var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
 var dayOfYear = ((today - onejan + 1)/86400000);
 return Math.ceil(dayOfYear/7)
};

$("#MyChart1_CustomFilterSelect_Week").val(new Date().getWeek()-1).change();
}

2nd Place - Ericsson & North Texas Food Bank Hackathon

The “Hackathon” was a programming competition sponsored by Ericsson to solve some of the North Texas Food Bank’s problems.

We made a scheduling system that allows people to see which days need more volunteers, then sign up to volunteer. The coolest part is that it would call people with a prerecorded message reminding them of their appointment.

Calculate Weeks In Sharepoint

=INT((Created-DATE(YEAR(Created),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Created),0,1)),"d")))/7)+1

This is a modified version of this formula which didn't give me the correct week number (maybe due to regional settings?): http://lamahashim.blogspot.com/2009/10/sharepoint-calculated-field-week-number.html 

It matches the number of weeks calculated in excel and all the calculators I could find on the internet.

Update: I also needed to add a 0 before the "Week" if the number is less than 10, because it will cause an error in sorting otherwise.

Here's the formula to add a 0 if the number is less than 10:
=IF((INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1)<10,"0"&(INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1),(INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1))&" "

(Note: the &" " part forces it to be a string rather than a floating point value)

Impressive Javascript

https://github.com/mbostock/d3/wiki/Gallery

"D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation."

Google Charts - GeoMap vs GeoChart

GeoMap - The map is rendered in the browser using an embedded Flash player.

GeoChart - Rendered using SVG

I noticed the GeoChart loads faster (at least in Chrome).