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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.