October 05, 2015, 11:52 AM
kotiCreating Barchart by using ibiDatagrid in Action sctipt
Hi All,
I have the below code it reads the data from Arraycollection. But i want to create graph from datagrid and grid is loading the data from fex file. Any suggestions please. Below is the mxml reference code. Thanks!
<?xml version="1.0"?>
<!-- charts/CreateChartInActionScript.mxml -->
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="init()"
height="600">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script><![CDATA[
import mx.collections.ArrayCollection;
import mx.charts.BarChart;
import mx.charts.series.BarSeries;
import mx.charts.CategoryAxis;
import mx.charts.Legend;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month:"Jan", Profit:2000, Expenses:1500},
{Month:"Feb", Profit:1000, Expenses:200},
{Month:"Mar", Profit:1500, Expenses:500}
]);
public var myChart:BarChart;
public var series1:BarSeries;
public var series2:BarSeries;
public var legend1:Legend;
public function init():void {
/* Create the chart object and set some
basic properties. */
myChart = new BarChart();
myChart.showDataTips = true;
myChart.dataProvider = expenses;
/* Define the category axis. */
var vAxis:CategoryAxis = new CategoryAxis();
vAxis.categoryField = "Month" ;
vAxis.dataProvider = expenses;
myChart.verticalAxis = vAxis;
/* Add the series. */
var mySeries:Array=new Array();
series1 = new BarSeries();
series1.xField="Profit";
series1.yField="Month";
series1.displayName = "Profit";
mySeries.push(series1);
series2 = new BarSeries();
series2.xField="Expenses";
series2.yField="Month";
series2.displayName = "Expenses";
mySeries.push(series2);
myChart.series = mySeries;
/* Create a legend. */
legend1 = new Legend();
legend1.dataProvider = myChart;
/* Attach chart and legend to the display list. */
p1.addElement(myChart);
p1.addElement(legend1);
}
]]></fx:Script>
<s:Panel id="p1" title="BarChart Created in ActionScript">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:Panel>
</s:Application>