how to change the data of line chart on datagrid itemclick in FLEX
I have created a line chart and another datagrid.based on dataitem clicked nthe chart should be changed. For example I have datagrid for stocks with 3 stocks GOOGL,Yahoo and ADBE .On clicking upon the GOOGL the google data should be loa开发者_如何转开发ded in to line chart.
Please help me...!!!!
There are going to be many different ways to accomplish this goal. The example I am giving here is based on `itemClick event on a datagrid, however you could also accomplish the same using bindings.
<fx:Script>
<![CDATA[
import mx.charts.series.LineSeries;
import mx.controls.dataGridClasses.DataGridItemRenderer;
[Bindable]
public var stocks:Array =
[
{
name: "goog",
values:
[
{ x:1, y:2 },
{ x:2, y:8 },
{ x:3, y:6 },
{ x:4, y:4 }
]
} ,
{
name: "ibm",
values:
[
{ x:1, y:12 },
{ x:2, y:4 },
{ x:3, y:5 },
{ x:4, y:6 }
]
}
];
protected function datagrid_itemClickHandler(event:ListEvent):void
{
var i:int;
i = 2;
var data:Object = (event.itemRenderer as DataGridItemRenderer).data;
var line:LineSeries = new LineSeries();
line.dataProvider = data.values;
line.xField = "x";
line.yField = "y";
chart.series = [line];
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<mx:LineChart id="chart" dataProvider="{stocks}">
</mx:LineChart>
<mx:DataGrid dataProvider="{stocks}"
itemClick="datagrid_itemClickHandler(event)"/>
精彩评论