开发者

Flex : dynamically created series doesnt show on the chart?

I have the follow class :

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" ); 

          开发者_C百科  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();

        }
    }
}

on the application i am trying the follow :

dinamicSeries : Array = new Array(); mySeries : TimeLineSeries = new TimeLineSeries( 'chronos' ); mySeries.rawData = randomData(); // it is a function which gain some random data mySeries.ApplyData(); dinamicSeries.push( mySeries );

mainChart.series = dinamicSeries;

The new series name appear on the chart, but the data doest, and the chart always remains blank. - What wrong I am doing ?


Did you affect a vertical axis to your newly created series ?


You need to make public var rawData into a getter/setter pair, so you can populate the ArrayCollection with it. So:

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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜