FLEX 动态添加线和轴

package   
02 {    
03         import mx.charts.CategoryAxis;    
04         import mx.charts.Legend;    
05         import mx.charts.LineChart;    
06         import mx.charts.series.LineSeries;    
07         import mx.collections.ArrayCollection;    
08         import mx.containers.HBox;    
09         import mx.containers.VBox;    
10    
11         public class createChat extends VBox    
12         {    
13                     
14                 /**    
15                  *    
16                  * @用于根据一个ArrayCollection生成多个lineChat    
17                  */   
18                 //用于保存各chat    
19                 public var chartArray:Array=new Array    
20                 private var Width:int = 400   
21                 private var Height:int = 300   
22                 private var fontColor:String = "0x000000"   
23                 /**    
24                  *    
25                  * @param S 主值    
26                  * @param A        相关条件    
27                  * @param D        dataProvider    
28                  *    
29                  *    
30                  */   
31                 public function createChat(S:String, A:Array, D:ArrayCollection):void    
32                 {    
33                         for (var i:int=0; i < A.length; i++)    
34                         {    
35                                 var _titleArr:Array=A[i].toString().split(",")    
36    
37                                 var lineChart:LineChart=new LineChart    
38                                 lineChart.width=Width    
39                                 lineChart.height=Height    
40                                 lineChart.setStyle("color", fontColor)    
41                                 lineChart.dataProvider=D;    
42    
43                                 var lineHAxis:CategoryAxis=new CategoryAxis()    
44                                 lineHAxis.categoryField=S;    
45                                 lineHAxis.dataProvider=D;    
46                                 lineChart.horizontalAxis=lineHAxis;    
47    
48                                 var myLineSeries:Array=new Array();    
49                                 for (var j:int=0; j < _titleArr.length; j++)    
50                                 {    
51                                         var lineSeries:LineSeries=new LineSeries();    
52                                         lineSeries.xField=S;    
53                                         lineSeries.yField=_titleArr[j];    
54                                         lineSeries.displayName=_titleArr[j];    
55                                         myLineSeries.push(lineSeries);    
56                                 }    
57                                 lineChart.series=myLineSeries;    
58    
59                                 var chartLegend:Legend=new Legend    
60                                 chartLegend.setStyle("color", fontColor)    
61                                 chartLegend.dataProvider=lineChart;    
62                                 lineChart.showDataTips=true;    
63              
64                                 var hbox:HBox=new HBox    
65                                 hbox.addChild(lineChart);    
66                                 hbox.addChild(chartLegend);    
67                                 this.addChild(hbox);    
68                                 chartArray.push(hbox);    
69                         }    
70                 }    
71                 public function removeAll():void{    
72                         this.removeAllChildren()    
73                 }    
74         }    
75 } 

文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/1_web/javascript/jsjs/20090826/172389.html
原文地址:https://www.cnblogs.com/zcy_soft/p/1970968.html