PDA

View Full Version : Chart and data provider problem


barby
12-20-2006, 09:24 PM
Hi all!

I have a problem: my chart is not refresh height of one column in ColumnChart when I change a property.

Here is my code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month: "Jan", x: 2000},
{Month: "Feb", x: 1000},
{Month: "Mar", x: 1500}]);

function myfun ():void {
expenses[0].x -= 100;
trace (expenses[0].x);
}

</mx:Script>
<mx:Button label="Button" click="myfun();"/>
<mx:Panel>
<mx:ColumnChart id="column" dataProvider="{expenses}">
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider="{expenses}" categoryField="Month"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries xField="Month" yField="x" displayName="x"/>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{column}"/>
</mx:Panel>
</mx:Application>

Thanks for advice! :)

dr_zeus
12-20-2006, 10:18 PM
Try this:

function myfun ():void {
var firstItem:Object = expenses[0];
firstItem.x -= 100;
expenses.setItemAt(firstItem, 0);
trace (expenses[0].x);
}

If you want components to refresh properly when you change data, ArrayCollections provide useful functions like setItemAt that are designed to dispatch events specifically for binding.

barby
12-20-2006, 10:42 PM
Thank you! :)