flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From modjkl...@comcast.net
Subject how to dynamically add multiple LineSeries to a chart?
Date Wed, 17 Apr 2013 17:04:31 GMT
Hello, I'm looking for help for the *proper* way to dynamically set multiple LineSeries for
a chart. I've provided the outline of my code below. 


I have a chart that can plot anywhere from 0 to some large number of LineSeries depending
on the user's actions. I declare these LineSeries as an array (csArray) in an <fx:Declarations>
block, which is later used in ActionScript function invalidateChart(). 


In using Flash Builder 4.6's memory profiler, I've noticed something interesting that makes
me think something is broken with my code below. If I run the program and select a first plot
with seven LineSeries. The chart renders fine. Then I select a second plot, which has a different
set of seven LineSeries, which also renders fine. Now I look at the memory usage: 


Class=LineSeriesItem 
Package= mx.charts.series.items 
Cumulative Instances=2370 
Instances=2370 
Cumulative Memory=455050 (4.26%) 
Memory=455050 (11.68%) 


Next, I repeat the plotting of the above charts in the same order. That is, I re-select the
option that plots the first chart that I looked at earlier (with 7 LineSeries). Then I select
the options to plot the second chart that I looked at earlier (with a different set of 7 LineSeries
compared to the first plot, but the same 7 LineSeries that I viewed for the second plot above).
I would expect the memory usage to be unchanged from above. But what I see is a 3.9x increase
in memory by LineSeriesItem: 



Class=LineSeriesItem 
Package= mx.charts.series.items 
Cumulative Instances=11577 
Instances=9207 
Cumulative Memory=2222784 (10.62) 
Memory=1767744 (28.14%) 


I don't understand why the memory increases from above... Is this normal behavior? 


If I repeat the plotting of the above two charts just like above (e.g. a third, or forth,
or fifth, etc., time), the memory no longer increases for LineSeriesItems, regardless of how
many times I repeat it. 


Please set me straight how to dynamically add LineSeries the proper way. Thanks for any help/advice.



-----my code follows----- 



<fx:Declarations> 

<fx:Array id="csArray"> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries /> <mx:LineSeries
/> <mx:LineSeries /> <mx:LineSeries /> 
<mx:LineSeries /> <mx:LineSeries /> 
</fx:Array> 
... 
</fx:Declarations> 


<fx:Script> 
<![CDATA[ 
... 
private var myData:Array; 
private var visArray:Array; 


public function invalidateChart():void { 

for (var ii:int=0;ii<myData.length;ii++) { 


var ls:LineSeries=csArray[ii]; 
ls.xField="x"; 
ls.yField="y"; 
ls.filterData=false; 


ls.setStyle("lineStroke",new SolidColorStroke(0x00FF00,10,1,true,"normal","square","round",3));

var cf:ClassFactory=new ClassFactory(com.myCompany.myrenderers.myLineRenderer); 
ls.setStyle("lineSegmentRenderer",cf); 
ls.setStyle("form","segment"); 
ls.dataProvider=myData[ii]; 
ls.y=-2; // shift plot up 
ls.x=1; // shift plot right 
} 


// only use those series for which visArray[i]=true 
var arr:Array=new Array(); 
for (var i:int=0;i < visArray.length;i++) { 
if(visArray[i]) 
arr.push(csArray[i]); 
} 
chart.series=arr; 


chart.invalidateDisplayList(); 
} 

... 
]]> 
</fx:Script> 


<myComponents:myLineChartComponent id="chart" ... /> 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message