I don't have too much time to post, as I am at work, but here is a snippet of a project I've been working on that might help:
//Dump current series to array var allSeries:Array = bigChart.series; //Set chart series to the array bigChart.series = allSeries; //Create series var newModel:LineSeries = new LineSeries(); //Put the items into a new array collection var tmp:ArrayCollection = new ArrayCollection(allSeries); //Add the series tmp.addItemAt(newModel,0); //Reset the series array to the source of the array collection allSeries = tmp.source; Probably not the best way to do this, but I can attest that it does work. --- In flexcoders@yahoogroups.com, "windsail05" <[EMAIL PROTECTED]> wrote: > > Having some troubles dynamically adding a line to a line chart. The > code below adds a line when you click a button but deletes all the > others. So the only line is the last one created. > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" width="100%" height="100%"> > <mx:Script> > <![CDATA[ > import mx.charts.AxisRenderer; > import mx.charts.CategoryAxis; > import mx.collections.ArrayCollection; > import mx.charts.series.LineSeries; > import mx.charts.chartClasses.DataDescription; > > private var i:int = 0; > [Bindable] private var aData:ArrayCollection = new ArrayCollection; > private var second:Date = new Date; > private var start:Number = new Number; > private var end:Number = new Number; > > public function buttonClick():void > { > addLine('line', createData("line"+i), 'display', "curve") > } > > public function addLine(displayName:String, > dataProvider:ArrayCollection, yField:String, Form:String):void > { > var ls:LineSeries = new LineSeries(); > ls.displayName = "Line"+i; > ls.dataProvider = dataProvider; > ls.yField = "name"; > ls.xField = "x"; > > var series:Array = linechart.series; > > series.push(ls); > > linechart.series. = series; > > //linechart.addChild(series); > //linechart.series[i] = new ChartLine(displayName, dataProvider, > yField, Form); > //linechart.validateDisplayList(); > ++i; > } > > public function createData(name:String):ArrayCollection > { > //aData.removeAll(); > > for(var j:uint=0; j<20; j++) > { > start = randomNumber(end); > end = randomNumber(start); > aData.addItem({"name":i*10, "x": start}); > aData.addItem({"name":i*10, "x": end}); > } > start =0; > end=0; > return aData; > } > > public function randomNumber(greaterThan:Number):Number > { > return (Math.random()*10) + greaterThan; > } > ]]> > </mx:Script> > <mx:LineChart x="0" y="0" id="linechart" width="100%" height="100%"/> > > <mx:Legend dataProvider="{linechart}" x="838"/> > > <mx:Button x="214" y="21" label="add line" click="buttonClick()"/> > > </mx:Application> >