Flex:动态创建的系列不在图表上显示?

时间:2011-10-13 14:56:46

标签: actionscript-3 flex flex4 flex4.5

我有以下课程:

package my.controls.charts.series
{
    import mx.charts.series.LineSeries;
    import mx.collections.ArrayCollection;
    import mx.graphics.SolidColorStroke;

    import my.controls.charts.ICommonCharts;

    public class TimeLineSeries extends LineSeries implements ICommonCharts
    {
        [Bindable]
        protected  var dataProviderLineSeries : ArrayCollection;
        public     var rawData                : Array; 

        public function TimeLineSeries( seriesName : String )
        {
            super();
            this.displayName  = seriesName;
            this.yField       = "value";
            this.xField       = "dateBegin";

            this.sortOnXField = true;
            this.filterData   = true;           

            this.setStyle( "form", "segment" ); 

            var stroke : SolidColorStroke = new SolidColorStroke();
                stroke.color    = 0xFF0000;
                stroke.weight   = 1;
            this.setStyle( "lineStroke", stroke );

            rawData                = new Array();
            dataProviderLineSeries = new ArrayCollection();
            this.dataProvider      = dataProviderLineSeries;
        }

        public function Clear() : void
        {
            rawData = [];
            dataProviderLineSeries.removeAll();
        }

        public function ApplyData() : void
        {
            dataProviderLineSeries.removeAll();
            dataProviderLineSeries = new ArrayCollection( rawData );
            dataProviderLineSeries.refresh();

        }
    }
}

我正在尝试以下应用程序:

dinamicSeries:Array = new Array(); mySeries:TimeLineSeries =新的TimeLineSeries('chronos'); mySeries.rawData = randomData(); //它是一个获取一些随机数据的函数 mySeries.ApplyData(); dinamicSeries.push(mySeries);
mainChart.series = dinamicSeries;

新系列名称显示在图表上,但数据会显示,图表始终为空白。 - 我做错了什么?

2 个答案:

答案 0 :(得分:1)

您需要将public var rawData转换为getter / setter对,以便可以使用它填充ArrayCollection。所以:

protected var _rawData:Array;

public function get rawData():Array {
    return _rawData;
}
public function set rawData(value:Array):void {
    if (value != _rawData) {
       _rawData = value;
       dataProviderLineSeries.source = value;
    }
}

答案 1 :(得分:1)

您是否影响了新创建的系列的垂直轴?