The series property is a plain array so LineChart won't detect changes to it directly.  You need to force series invalidation by assigning the series array itself.  Here's an example:
 
<?xml version="1.0"?>
<mx:Application
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute"
 creationComplete="addMoreSeries();">
 
<mx:Script>
 <![CDATA[
  import mx.charts.series.LineSeries;
  
  import mx.collections.ArrayCollection;
  
  [Bindable]
  private var stocksAC:ArrayCollection = new ArrayCollection( [
            { Date: "2006-10-25", Stock1: 2000, Stock2: 150, Stock3: 450 },           
            { Date: "2006-10-26", Stock1: 1000, Stock2: 200, Stock3: 600 },           
            { Date: "2006-10-27", Stock1: 1500, Stock2: 500, Stock3: 300 },
            { Date: "2006-10-28", Stock1: 1800, Stock2: 120, Stock3: 900 },           
            { Date: "2006-10-29", Stock1: 2400, Stock2: 575, Stock3: 500 } ]);
       
        private function addMoreSeries():void {
         
         var series:LineSeries = new LineSeries();
         series.yField = "Stock2";
         series.form = "curve";
         linechart.series.push(series);
 
         series = new LineSeries();
         series.yField = "Stock3";
         series.form = "curve";
         linechart.series.push(series);
 
   // force series invalidation since invalidateSeries
   // is protected
   linechart.series = linechart.series;
        }
 ]]>
</mx:Script>
<mx:LineChart id="linechart" dataProvider="{stocksAC}">                           
 <mx:horizontalAxis>               
  <mx:CategoryAxis categoryField="Date"/>
 </mx:horizontalAxis>           
 
 <mx:series>               
  <mx:LineSeries yField="Stock1" form="curve" displayName="Adobe"/>               
    </mx:series>       
</mx:LineChart>
 

</mx:Application>
HTH,

Sam
 
 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Brown
Sent: Tuesday, October 31, 2006 5:01 PM
To: [email protected]
Subject: [flexcoders] Linechart with dynamic series?

I was wondering if it is possible to dynamically add LineSeries to a LineChart component at run-time?
I'd like to create something like a stock chart where the user can select multiple stocks to display on the stock chart.

How would I format the arrayCollection being used as a dataProvider for the LineChart? My initial guess would be something like this, except it would be coming from a web service:
private var stocksAC:ArrayCollection = new ArrayCollection( [

{ Date: "2006-10-25", Stock1: 2000, Stock2: 150, Stock3: 450 },
{ Date: "2006-10-26", Stock1: 1000, Stock2: 200, Stock3: 600 },
{ Date: "2006-10-27", Stock1: 1500, Stock2: 500, Stock3: 300 },
{ Date: "2006-10-28", Stock1: 1800, Stock2: 120, Stock3: 900 },
{ Date: "2006-10-29", Stock1: 2400, Stock2: 575, Stock3: 500 } ]);
]]>
One issue I am having is how to dynamically add properties to the objects in the stocksAC arrayCollection. What do I do if I want to add a forth stock or fifth stock at runtime?

Another issue is how to add LineSeries at runtime?
<mx:LineChart id="linechart" dataProvider="{stocksAC}">

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

<mx:series>
<mx:LineSeries yField="Stock1" form="curve" displayName="Adobe"/>
<mx:LineSeries yField="Stock2" form="curve" displayName="Microsoft"/>
<mx:LineSeries yField="Stock3" form="curve" displayName="Apple"/>
</mx:series>
</mx:LineChart>
Again, how do I add a forth or fifth stock at runtime?

I hope this is clear enough.

Cheers,
BB

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to