Chart out of SharePoint data without Stacked

Step 1: Create a sharepoint list with the following data in it.

Step 2: Below code creates the bar chart

<?xml version=”1.0″ encoding=”utf-8″?><mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute” creationComplete=”onCreate(event)”><mx:Script><![CDATA[

import mx.charts.series.*;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.binding.utils.BindingUtils;
import mx.charts.*;
import mx.core.UIComponent;

private var MainXMLList:XMLList;
private var Project:Array =new Array();
private var Status:Array =new Array();
private var BU:Array =new Array();
private var MainXML:URLLoader;

[Bindable]
public var HoldStatus:ArrayCollection=new ArrayCollection();

private function onCreate(e:Event):void
{
MainXML=new URLLoader(new URLRequest(“http://teams4.sharepoint.hp.com/teams/ProjSpace/_vti_bin/owssvr.dll?Cmd=Display&List={56FD41DB-4D68-43EF-AF9F-3A76CBC0A8CC}&XMLDATA=TRUE”))
MainXML.addEventListener(Event.COMPLETE,MainXMLL)
}

private function MainXMLL(e:Event):void
{
var myXML:XML = XML(e.target.data);
var XMLL:XMLList=new XMLList(e.target.data)
var rsNS:Namespace = XMLL.namespace(“rs”);
var zNS:Namespace = XMLL.namespace(“z”);
var sNS:Namespace = XMLL.namespace(“s”);
MainXMLList=new XMLList(XMLL.rsNS::data.zNS::row)
HoldStatus.source=[]
for(var i:int=0;i<MainXMLList.length();i++)
{
BU.push(MainXMLList[i].attribute(“ows_Project_x0020_BU”))
Status.push(MainXMLList[i].attribute(“ows_Status”))
}
BU=removeDuplicates(BU)
Status=removeDuplicates(Status)
for(var b:int=0;b<BU.length;b++)
{
HoldStatus.source.push({Dummy:”April”})  // Just pushing dummy value to create an empty index
HoldStatus[b][“Title”]=BU[b]  // Creating a Title Idenfier in Arraycollection which stores BU1 and BU2
for(var s:int=0;s<Status.length;s++)
HoldStatus[b][Status[s]]=MainXMLList.(attribute(“ows_Project_x0020_BU”)== BU[b] && attribute(“ows_Status”) == Status[s] ).length()  //If Project BU =”BU1″ and Status =”Pipleline” Takes the count.
}

var myChart:BarChart = new BarChart(); // Create barchart dynamically
myChart.dataProvider = HoldStatus; //Assigning the HoldStatus (Arraycollection as a dataprovider for BarChart

// Setting up the Vertical Axis
var vAxis:CategoryAxis = new CategoryAxis();
vAxis.categoryField = “Title”;
myChart.verticalAxis = vAxis;
var hh:LinearAxis=new LinearAxis()
hh.interval=1
myChart.horizontalAxis=hh

 //Creating barseries (Pipeline, Closed, Complete) where Status array

holds “Pipeline, Closed and Complete”
for(var c:int=0;c<Status.length;c++)
{
var BS:BarSeries = new BarSeries();
BS.xField = Status[c];
BS.displayName = Status[c];
myChart.series.push(BS) //Pushes all bar series into Chart
}

myChart.percentWidth=95;
myChart.percentHeight=80;
var l:Legend = new Legend();
l.dataProvider = myChart;
l.direction=”horizontal”
l.percentWidth=95;
l.percentHeight=20;

myPanel.addChild(myChart);
myPanel.addChild(l);
}
private function removeDuplicates(arr:Array):Array  // This function retrieves the unique values from the Array
{
var currentValue:String = “”;
var tempArray:Array = new Array();
arr.sort(Array.CASEINSENSITIVE);
arr.forEach(
function(item:*, index:uint, array:Array):void {
if (currentValue != item) {
tempArray.push(item);
currentValue= item;
}
}
);

return tempArray;

}

]]>

</mx:Script>

<mx:Panel id=”myPanel” width=”300″ height=”300″>

</mx:Panel>

</mx:Application>

 

 

This will collect all BU Values and Status
for(var i:int=0;i<MainXMLList.length();i++)
{
BU.push(MainXMLList[i].attribute(“ows_Project_x0020_BU”))
Status.push(MainXMLList[i].attribute(“ows_Status”))
}Below code retrieves unique values and stores back into the same
array variable
BU=removeDuplicates(BU)Status=removeDuplicates(Status)Below code construct a loop for BUs and inner loop for status to
get the count of projects

for(var b:int=0;b<BU.length;b++)
{
HoldStatus.source.push({Dummy:”April”})
HoldStatus[b][“Title”]=BU[b]
for(var s:int=0;s<Status.length;s++)
HoldStatus[b][Status[s]]=MainXMLList.(attribute(“ows_Project_x0020_BU”)== BU[b] && attribute(“ows_Status”) == Status[s] ).length()
}

This will create an array collection like below 

{Title :BU1 , Pipeline: 2, Closed: 2}
{Title :BU2 , Pipeline: 1, Closed: 2}

Output

Chart out of SharePoint data

Step 1: Create a sharepoint list with the following data in it.

Step 2: Below code creates the bar chart

<?xml version=”1.0″ encoding=”utf-8″?><mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute” creationComplete=”onCreate(event)”>

<mx:Script>

<![CDATA[

import mx.charts.series.*;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.binding.utils.BindingUtils;
import mx.charts.*;
import mx.core.UIComponent;

private var MainXMLList:XMLList;
private var Project:Array =new Array();
private var Status:Array =new Array();
private var BU:Array =new Array();
private var MainXML:URLLoader;

[Bindable]
public var HoldStatus:ArrayCollection=new ArrayCollection();

private function onCreate(e:Event):void
{
MainXML=new URLLoader(new URLRequest(“http://teams4.sharepoint.hp.com/teams/ProjSpace/_vti_bin/owssvr.dll?Cmd=Display&List={56FD41DB-4D68-43EF-AF9F-3A76CBC0A8CC}&XMLDATA=TRUE”))
MainXML.addEventListener(Event.COMPLETE,MainXMLL)
}

private function MainXMLL(e:Event):void
{
var myXML:XML = XML(e.target.data);
var XMLL:XMLList=new XMLList(e.target.data)
var rsNS:Namespace = XMLL.namespace(“rs”);
var zNS:Namespace = XMLL.namespace(“z”);
var sNS:Namespace = XMLL.namespace(“s”);
MainXMLList=new XMLList(XMLL.rsNS::data.zNS::row)
HoldStatus.source=[]
for(var i:int=0;i<MainXMLList.length();i++)
{
BU.push(MainXMLList[i].attribute(“ows_Project_x0020_BU”))
Status.push(MainXMLList[i].attribute(“ows_Status”))
}
BU=removeDuplicates(BU)
Status=removeDuplicates(Status)
for(var b:int=0;b<BU.length;b++)
{
HoldStatus.source.push({Dummy:”April”})  // Just pushing dummy value to create an empty index
HoldStatus[b][“Title”]=BU[b]  // Creating a Title Idenfier in Arraycollection which stores BU1 and BU2
for(var s:int=0;s<Status.length;s++)
HoldStatus[b][Status[s]]=MainXMLList.(attribute(“ows_Project_x0020_BU”)== BU[b] && attribute(“ows_Status”) == Status[s] ).length()  //If Project BU =”BU1″ and Status =”Pipleline” Takes the count.
}

var myChart:BarChart = new BarChart(); // Create barchart dynamically
myChart.dataProvider = HoldStatus; //Assigning the HoldStatus (Arraycollection as a dataprovider for BarChart

// Setting up the Vertical Axis
var vAxis:CategoryAxis = new CategoryAxis();
vAxis.categoryField = “Title”;
myChart.verticalAxis = vAxis;
var hh:LinearAxis=new LinearAxis()
hh.interval=1
myChart.horizontalAxis=hh

 // Setting up the chart type as stacked bar
var innerSet:BarSet = new BarSet();
innerSet.type = “stacked”;

 //Creating barseries (Pipeline, Closed, Complete) where Status array
holds “Pipeline, Closed and Complete”
for(var c:int=0;c<Status.length;c++)
{
var BS:BarSeries = new BarSeries();
BS.xField = Status[c];
BS.displayName = Status[c];
innerSet.series.push(BS) // innerSet is the barSet where all Bar Series
into the InnerSet, It groups the series into stacked show
}

myChart.series=[innerSet] // Assigning the Barset to the chart
myChart.percentWidth=95;
myChart.percentHeight=80;
var l:Legend = new Legend();
l.dataProvider = myChart;
l.direction=”horizontal”
l.percentWidth=95;
l.percentHeight=20;

myPanel.addChild(myChart);
myPanel.addChild(l);
}
private function removeDuplicates(arr:Array):Array  // This function retrieves the unique values from the Array
{
var currentValue:String = “”;
var tempArray:Array = new Array();
arr.sort(Array.CASEINSENSITIVE);
arr.forEach(
function(item:*, index:uint, array:Array):void {
if (currentValue != item) {
tempArray.push(item);
currentValue= item;
}
}
);

return tempArray;

}

]]>

</mx:Script>

<mx:Panel id=”myPanel” width=”300″ height=”300″>

</mx:Panel>

</mx:Application>

This will collect all BU Values and Status
for(var i:int=0;i<MainXMLList.length();i++)
{
BU.push(MainXMLList[i].attribute(“ows_Project_x0020_BU”))
Status.push(MainXMLList[i].attribute(“ows_Status”))
}Below code retrieves unique values and stores back into the same
array variable
BU=removeDuplicates(BU)

Status=removeDuplicates(Status)

Below code construct a loop for BUs and inner loop for status to
get the count of projects

for(var b:int=0;b<BU.length;b++)
{
HoldStatus.source.push({Dummy:”April”})
HoldStatus[b][“Title”]=BU[b]
for(var s:int=0;s<Status.length;s++)
HoldStatus[b][Status[s]]=MainXMLList.(attribute(“ows_Project_x0020_BU”)== BU[b] && attribute(“ows_Status”) == Status[s] ).length()
}

This will create an array collection like below 

{Title :BU1 , Pipeline: 2, Closed: 2}
{Title :BU2 , Pipeline: 1, Closed: 2}

 

Output

Advanced Datagrid from SharePoint data

Step 1: Create a sharepoint list with the following data in it.

Step 2: Retrieving custom list data as XML in flex. In order to create the
advanced datagrid with grouping (Column grouping lets you collect multiple
columns under a single column heading)

<?xml version=”1.0″ encoding=”utf-8″?><mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute” initialize=”initializeHandler();” ><mx:Script>
<![CDATA[
import mx.controls.Alert
import mx.controls.dataGridClasses.DataGridColumn
import mx.collections.*;
private var FinalXML:XMLList
[Bindable]
private var dpFlat:ArrayCollection=new ArrayCollection();
private function initializeHandler():void
{
var XMLLoader:URLLoader=
new URLLoader(new URLRequest(“<sharepointLini>/_vti_bin/owssvr.dll?Cmd=Display&List=%7BA6FFA525%2D0AC1%2D411E%2DA1F4%2D687402312595%7D&XMLDATA=TRUE”))
XMLLoader.addEventListener(Event.COMPLETE,openXMLValues)
function openXMLValues(e:Event):void
{
var XMLL:XML=new XML(e.target.data)
var rsNS:Namespace = XMLL.namespace(“rs”);
var zNS:Namespace = XMLL.namespace(“z”);
var sNS:Namespace = XMLL.namespace(“s”);
FinalXML=new XMLList(XMLL.rsNS::data.zNS::row)
var Obj:Object
for(var i:int=0;i<FinalXML.length();i++)
{
var attNames:XMLList = FinalXML[0].attributes();
Obj=new Object();
for (var i:int=0; i<attNames.length(); i++)
{
Obj[attNames[i].name().toString()]=attNames[i]
}
dpFlat.addItem(Obj)
}
}

}

]]>
</mx:Script>

<mx:Panel title=”AdvancedDataGrid Control Example”
height=”300″ width=”400″ layout=”horizontal”
paddingTop=”10″ paddingBottom=”10″ paddingLeft=”10″ paddingRight=”10″>

<mx:AdvancedDataGrid id=”myADG”>

<mx:dataProvider>
<mx:GroupingCollection2 id=”gc” source=”{dpFlat}”>
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name=”ows_LinkTitle”/>
<mx:GroupingField name=”ows_Category2″/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection2>
</mx:dataProvider>

<mx:columns>
<mx:AdvancedDataGridColumn dataField=”ows_LinkTitle” headerText=”Category1″/>
<mx:AdvancedDataGridColumn dataField=”ows_Category2″ headerText=”Category2″/>
<mx:AdvancedDataGridColumn dataField=”ows_Value” headerText=”Value”/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Panel>
</mx:Application>

Notes: XMLList values should be converted to ArrayCollection. ArrayCollection
will hold Objects. Grouping in advanced datagrid cannot be XMLList without
having a hierarchial data.

If XML value is like Below
<item value=”server”>
<citem value=”Integrity” >
<sitem value=”580i” />
<sitem value=”670i” />
</citem>
</item>

It can be treated as Hierarchical data and can be set as datasource to advanced
Datagrid. In this case, Group is very simple.

But Sharepoint gives the XML structure as

<z:row ows_Attachments=”0″ ows_LinkTitle=”Server” ows_Category2=”ProLiant”ows_Value=”580i” />
<z:row ows_Attachments=”0″ ows_LinkTitle=”Server” ows_Category2=”ProLiant”ows_Value=”670i”/>
<z:row ows_Attachments=”0″ ows_LinkTitle=”Server” ows_Category2=”Integrity”ows_Value=”580i”/>
<z:row ows_Attachments=”0″ ows_LinkTitle=”Server” ows_Category2=”Integrity”ows_Value=”780i2″/>
 
So this needs to be converted to either hierarchical XML structure or Array Collection like below dynamically

DP:   var ArrayCollection=new ArrayCollection(
{ows_Attachments:”0″, ows_LinkTitle:”Server”,ows_Category2:”ProLiant”, ows_Value:”580i”}
{ows_Attachments:”0″, ows_LinkTitle:”Server”,ows_Category2:”ProLiant”, ows_Value:”670i”}
{ows_Attachments:”0″, ows_LinkTitle:”Server”,ows_Category2:”Integrity”, ows_Value:”580i”}
{ows_Attachments:”0″, ows_LinkTitle:”Server”,ows_Category2:”Integrity”, ows_Value:”780i”}
)
for(var i:int=0;i<FinalXML.length();i++)
{
var attNames:XMLList = FinalXML[0].attributes(); // It retrieves all attributes from the xml node
Obj=new Object();
for (var i:int=0; i<attNames.length(); i++)  // Loop through attributes and create object with identifier name as attribute
{
Obj[attNames[i].name().toString()]=attNames[i]  // Creating identifier in object and assign the attribute values from xml.
}
dpFlat.addItem(Obj)  // add Object into the ArrayCollection (sample ows_Attachments:”0″, ows_LinkTitle:”Server”, ows_Category2:”ProLiant”, ows_Value:”580i” )

Output

Web Services in SharePoint 2007

This tutorial shows how to access the user names from People or Groups using

SharePoint webservices

Step 1: On DataSource Library pane, XML Web Services is the option to invoke
web services.

Step 2: Paste the web services link (https://<sharepointLocation>/_vti_bin/usergroup.asmx?WSDL)
for the user group data and click on connect. This will retrieve data of people.

In this below screenshot, GetUserCollectionFromGroup is an operation which retrieves the
people details belongs to the specified group name.

Step 3: Once the operation selected, it will show the parameters required for
that operation. In this case, groupName is the input parameter for
GetUserCollectionFromGroup. I have created a NewGroup group in my sharePoint. So
here i am passing “NewGroup” to that operation.

Step 4: Click on Login tab. Enter Username and password to establish the
connection

Step 5: Now click on show data, it will show all the data.

Step 6: Select Name and click on Insert Selected Fields and select multiple item
view

Step 7: This will show the data into the screen . The next step is to filter
the data based on the current login.

in the above screenshot, UserID needs included in order to use the CAMLVariable
UserID.

Step 8: Please change the below code to see if the current user name exists in
the group

In order to get the Number
of Rows
<xsl:variable name=”Rows” select=”/soap:Envelope/soap:Body/ddw1:GetUserCollectionFromGroupResponse/ddw1:GetUserCollectionFromGroupResult/ddw1:GetUserCollectionFromGroup/ddw1:Users/ddw1:User”/>

to<xsl:variable name=”Rows” select=”/soap:Envelope/soap:Body/ddw1:GetUserCollectionFromGroupResponse/ddw1:GetUserCollectionFromGroupResult/ddw1:GetUserCollectionFromGroup/ddw1:Users/ddw1:User[@Name=$UserID]“/>
<table>
<tr><td>
<xsl:value-of select=”$count(Rows)” />
</td></tr>

</table>

Dynamically add Movieclip to Scrollpane AS3

Step 1: Create Movieclip Title which needs to be added dynamically into

Scrollpane. Make sure you have checked “Export for Actionscript”. This will
automatically create Class name “Title”

Step2 : Inside Title Movie clip , insert texttool and an Image. Convert that
image to symbol and give instance name “Ico”

Instance name for TextTool is TxtValue

Step 3: Insert ScrollPane in Scene1 and give instance name MainScroll

Step 4 : Paste the code below in scene1 actionscript panel.

var S:MovieClip=new MovieClip()  // Create empty movieClipMainScroll.source=S // Assign empty movieclip to the scrollpane. It is mandatory to assign empty movie clicp to scrollpane before you do anything dynamically with scrollpanefor(var i=0;i<5;i++)   // Constructing a loop to create 5 movieclips dynamically
{
var T:Title=new Title() // Create the MovieClip (Title) and assign it to the variable T

T.y=i*30  // Set y axis value for the T
T.Txt.text=”Title” +i //Setting up the Txt value dynamic
T.Ico.id=i // Title movie clip already holds another movieclip named Ico  the movieclips
T.Ico.addEventListener(MouseEvent.CLICK,GetID) // Add eventlistener for that Ico .
MovieClip(MainScroll.content).addChildAt(T,i) //addChild will be used when u add anything to the movieclip. So here the scrollpane content needs to be treated as Movieclip , So MovieClip(MainScroll.Content) will be treated as Movieclip
}

function GetID(e:Event)
{
trace(e.target.id) // e.target points to the Ico movieclip.. Where in id been stored into Ico. So it gives you the respective id numbers.
}

Output

Codes Explanation

MainScroll.source=SAssign empty movieclip to the scrollpane. It is
mandatory to assign empty movie clicp to scrollpane before you do
anything dynamically with scrollpane
MovieClip(MainScroll.content).addChildAt(T,i)
addChild will be used when u add anything
to the movieclip. So here the scrollpane content needs to be treated as
Movieclip , So MovieClip(MainScroll.Content) will be treated as
Movieclip

attachMovie Clip in AS3

attachMovie syntax doesn’t work with Action Script 3.0. Each movieclips are considered as classes in Actionscript 3.0

Step 1: Insert Symbol -> Type MovieClip , Select export for actionscript

Step 2: Make a Note of the Class name

Step 3: Drag texttool and put some static text

Step 4: In Frame 1 paste the below code.

var MC:Symbol1=new Symbol1() //Symbol1 is the classname for the movieclip
addChild(MC)
MC.x=100
MC.y=200

Save XML in flash

This article shows how to create XML and store it into a Local Machine without any dialog box.
In order to avoid the dialog box and save with full security, Adobe Air is the best option. FileStream from Adobe Air has the reliability to save the file without any user interaction

Step 1. Create one Sample XML file in C:\test.xml with <sample></sample>

Step 2: Create two textboxes and one save button with instances name uid , pwd and saveBtn

Step 3. The code below

import flash.filesystem.*;
var LoadXML=new URLLoader(new URLRequest(“c://test.xml”)) // Loading XML file
LoadXML.addEventListener(Event.COMPLETE,LoadXMLFunction) // on load of XML calls LoadXMLFunction
saveBtn.addEventListener(MouseEvent.CLICK,onSave) // on save button click calls onSave
var MainXML:XML;function LoadXMLFunction(e:Event)
{
MainXML=XML(e.target.data) //Load all XML data from test.xml to MainXML
trace(MainXML)
}
function onSave(e:Event):void
{
var item:XML = <citem /> // Create one XML Node
item.userId = uid.text // assign uid textbox value to userId node
item.pwd = pwd.text  // assign pwd textbox value to pwd node
MainXML.appendChild(item); // Append this xml item to MainXML 

var file:File = new File();
file = file.resolvePath(“c:\\test.xml”); // open test.xml 
var fileStream:FileStream = new FileStream(); // Create new FileStream to Perform Read or Write
fileStream.open(file, FileMode.WRITE); // Open file in WRITE Mode
fileStream.writeUTFBytes(MainXML);  //Write MainXML xml content to the file test.xml
fileStream.close(); //Close the File Stream
}