0

I am creating an ArrayCollection through a loop and afterwards want to use this ArrayCollection to build a line chart. The only problem is that I have only values in my ArrayCollection and no keywords, which are used to build a line chart. How can I add keywords to my ArrayCollection? Or is there a way to build a linechart without keywords?

here is the code of creating the arraycollection:

[Bindable] public var Graph_:ArrayCollection;

        public function populateArray():void {

        var Graph_:ArrayCollection = new ArrayCollection();

        for (var i:int=0; i<=500; i++){

            var depth_:Number = i*10;
            var pressure:Number = 100+i;
            Graph_.addItem([depth_,pressure]); 

            }
// I want to use it further in this way:

<mx:LineChart id="chart"
          dataProvider= "{Graph_}"
          showDataTips="true">

    <mx:horizontalAxis>
        <mx:CategoryAxis categoryField="Depth" />   
    </mx:horizontalAxis>

    <mx:series>
        <mx:LineSeries  yField="Pressure" form="curve" displayName="Pressure"/>
    </mx:series>

    </mx:LineChart>
4

1 回答 1

0

这就是@Brian Bishop 建议你做的:

public function populateArray():void {

    Graph_ = new ArrayCollection();
    for (var i:int=0; i<=500; i++) {

        var depth_:Number = i*10;
        var pressure:Number = 100+i;
        // add an object who's property names are "depth", "pressure"
        // use these names when configuring the axis/line series of the chart
        Graph_.addItem({ depth: depth_, pressure: pressure }); 
    }
}

当您向 中添加项目时ArrayCollection,将它们添加为包含您的数据的匿名对象。现在您可以告诉您的图表使用这些“关键字”(属性名称)。

注意:我也改变了这一行:Graph_ = new ArrayCollection();

Graph_您的代码使用了仅存在于函数内部的局部变量,它不是[Bindable] Graph_您在类中定义的变量。

于 2013-07-01T19:55:11.960 回答