向Flex中的LineChart中动态添加线
package
{
import mx.charts.CategoryAxis;
import mx.charts.Legend;
import mx.charts.LineChart;
import mx.charts.series.LineSeries;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.containers.VBox;
public class createChat extends VBox
{
/**
*
* @用于根据一个ArrayCollection生成多个lineChat
*/
//用于保存各chat
public var chartArray:Array=new Array
private var Width:int = 400
private var Height:int = 300
private var fontColor:String = "0x000000"
/**
*
* @param S 主值
* @param A 相关条件
* @param D dataProvider
*
*
*/
public function createChat(S:String, A:Array, D:ArrayCollection):void
{
for (var i:int=0; i < A.length; i++)
{
var _titleArr:Array=A[i].toString().split(",")
var lineChart:LineChart=new LineChart
lineChart.width=Width
lineChart.height=Height
lineChart.setStyle("color", fontColor)
lineChart.dataProvider=D;
var lineHAxis:CategoryAxis=new CategoryAxis()
lineHAxis.categoryField=S;
lineHAxis.dataProvider=D;
lineChart.horizontalAxis=lineHAxis;
var myLineSeries:Array=new Array();
for (var j:int=0; j < _titleArr.length; j++)
{
var lineSeries:LineSeries=new LineSeries();
lineSeries.xField=S;
lineSeries.yField=_titleArr[j];
lineSeries.displayName=_titleArr[j];
myLineSeries.push(lineSeries);
}
lineChart.series=myLineSeries;
var chartLegend:Legend=new Legend
chartLegend.setStyle("color", fontColor)
chartLegend.dataProvider=lineChart;
lineChart.showDataTips=true;
var hbox:HBox=new HBox
hbox.addChild(lineChart);
hbox.addChild(chartLegend);
this.addChild(hbox);
chartArray.push(hbox);
}
}
public function removeAll():void{
this.removeAllChildren()
}
}
}
文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/1_web/javascript/jsjs/20090826/172389.html