2009年4月3日星期五

繪製Sharepoint表單(List)的圖表(Chart)

在Sharepoint中可以用Excel service來製作圖表,但是資料來源卻不能是Sharepoint中的表單,市面上有不少的webpart配以flash來做到,但是要有質素的就要付錢,不用錢的質素卻令人卻步,加上用上他人的flash來製作,限制很大,不容易修改。

簡單講解整個流程
1) 利用ajax call Sharepoint web service來提取表單的內容。
2) 將內容編輯成所需要的格式
3) 使用javascript library Flotr 去繪畫圖表


在看了 http://darrenjohnstone.net/2007/06/15/drawing-charts-in-office-live/ 中的做法之後,得到了一點啟發,就是利用ajax與Sharepoint SOAP的web service去提取表單資料,但這示範中的後段部份是用flash,難易控制外觀,加上xslt transform真的不易處理,所以放棄了後面的部份,而只使用前段利用web service去提取資料的部份。

以下是這段source code的中心,簡單的示範如何去用ajax call sharepoint web service,只要明白這個部份,基本上就可以利用web service去做更多效果。

// Gets all of the list items in a specified list and view
// Params:
// list: list name
// view: view name
// columns: an array of column names in the view to retrieve
//
// Returns:
// The response XML from lists.asmx-->GetListItems or null on an error
this.getListItems = function(list, view, columns)
{
var a = new ActiveXObject("Microsoft.XMLHTTP");
var cols = "";
if(a == null) return null;
for (var i = 0; i < name="'">";
}
cols += "";

a.Open("POST", this.getRootUrl() + "_vti_bin/Lists.asmx", false);
a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
var d = ''
+ ""
+ ""
+ ""
+ "" + list + "";

if (view != "")
d += "" + view + "";
d += "" + cols + ""
+ "
"
+ "
"
+ "
";
a.Send(d);

if (a.status != 200)
return null;
else
return a.responseXML;
}
這一段就是利用ajax call的部份,值得留意的是firefox與其他非IE瀏覽器並不支援Microsoft.XMLHTTP 的,所以我使用了XMLHttpRequest來取代,讀取回來的是xml格式的表單數據,所以下一部份就是要在xml提取所需要的資料了。

未完待續...

2009年4月1日星期三

Google Chrome 帶你進入3D既網上世界

Google又有搞作,安裝Google Chrome with 3D之後,再配戴3D眼鏡,你就可以睇到3D既網頁啦。
http://www.google.com/intl/en/landing/chrome/cadie/