Saturday, February 2, 2013

Dynamic XML With Chart


<fx:Script>
<![CDATA[
import com.chart;

import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
public var Maindata:XML;
[bindable]
public var charttypeSTR:String="columnchart";
[bindable]
public var chartItem:Boolean=true;;
[bindable]
public var chartColor:Number=0;
[bindable]
public var redertype:String="CircleRenderer";
public function loaddata():void
{
var temp:chart=new chart();
grop.removeAllElements();
grop=temp.CreateColumnChart(grop,charttypeSTR,Temp,"@year","@value","@year",chartItem,redertype,chartColor);

}

public function load(e:Event):void
{
if(maindrop.selectedIndex==0)
{
charttypeSTR="columnchart";
pan.title="Collumn Chart";
thireddrop.enabled=false;
rend.visible=false;
loaddata();
}
else if(maindrop.selectedIndex==1)
{
charttypeSTR="linechart";
pan.title="Line Chart";
thireddrop.enabled=true;
rend.visible=true;
loaddata();
}
else if(maindrop.selectedIndex==2)
{
charttypeSTR="PieChart";
pan.title="Pie Chart";
thireddrop.enabled=false;
rend.visible=false;
loaddata();
}
}

public function load2(e:Event):void
{
if(thireddrop.selectedIndex==0)
{
rend.visible=true
chartItem=true;
loaddata();
}
else
{
rend.visible=false;
chartItem=false;
loaddata();
}
}
public function load3(e:Event):void
{

redertype=fourthdrop.selectedItem.toString();
loaddata();

}
public function showdata(e:Event):void
{
if(checkB.selected==true)
{
checkB.label="Default";
colorpick.enabled=false;
chartColor=0;
loaddata();
}
else
{
checkB.label="Choose Color";
colorpick.enabled=true;
chartColor=colorpick.selectedColor;
loaddata();
}
}
[Bindable]
public var dataxml:XML;
[Bindable]
public var datalist:XML=new XML('<Temp/>');;
[Bindable]
public var Temp:XML=new XML('<data/>');
public function aff():void
{
dataxml=new XML('<row/>');
dataxml.@value=txt1.text;
dataxml.@year=txt2.text;
Temp.appendChild(dataxml)
xmltxt.text=Temp;
loaddata();
txt1.text='';
txt2.text='';
}
public function clear():void
{
delete Temp.*;
xmltxt.text=Temp;
loaddata();
}
public function save():void
{
var file:FileReference=new FileReference();
file.save(xmltxt.text, "ChartXML.txt");
}

]]>
</fx:Script>














DEMO

DOWNLOAD SOURCE CODE

Tuesday, January 22, 2013

Ascending And Descending Order In XML


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<fx:XML id="xmlList" xmlns="">
<datas>
<data>
<xValue>Sal/Payroll</xValue>
<value0>5</value0>
</data>
<data>
<xValue>Discounts</xValue>
<value0>10</value0>
</data>
<data>
<xValue>Depreciation</xValue>
<value0>7</value0>
</data>
<data>
<xValue>Facilities</xValue>
<value0>1</value0>
</data>
<data>
<xValue>Technology</xValue>
<value0>3</value0>
</data>
<data>
<xValue>School Expense</xValue>
<value0>8</value0>
</data>
<data>
<xValue>Debt</xValue>
<value0>4</value0>
</data>
<data>
<xValue>Cap Exp</xValue>
<value0>9</value0>
</data>
<data>
<xValue>Benefits</xValue>
<value0>2</value0>
</data>
<data>
<xValue>Program</xValue>
<value0>6</value0>
</data>
</datas>
</fx:XML>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.Sort;
import mx.collections.SortField;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
public function sort():void
{
var z:XMLListCollection = new XMLListCollection(xmlList.data as XMLList);
var mySort:Sort = new Sort();
mySort.fields = [new SortField('value0',true,true,true)];
z.sort = mySort;
z.refresh();
txt2.text=z.toXMLString();
}
public function sort2():void
{
var z:XMLListCollection = new XMLListCollection(xmlList.data as XMLList);
var mySort:Sort = new Sort();
mySort.fields = [new SortField('value0',true,false,true)];
z.sort = mySort;
z.refresh();
txt2.text=z.toXMLString();
}
]]>
</fx:Script>
<s:Button label="Ascending Order" click="sort()" x="540" y="8"/>
<s:Button label="Descending Order" click="sort2()" x="658" y="8"/>
<s:TextArea id="txt1" text="{xmlList.data}" x="20" y="32" width="457" height="585" editable="false" fontWeight="bold"/>
<s:TextArea id="txt2" x="540" y="32" width="457" height="585" editable="false" fontWeight="bold"/>
<s:Label x="20" y="12" text="XML-Check The Value" fontWeight="normal" fontSize="16" textDecoration="underline" color="#C91010" textAlign="center"/>
</s:Application>