2010年9月10日 星期五
2010年9月9日 星期四
2010年9月8日 星期三
Flex Chart 動態 series
一般的圖表設計,會在 Tag mx:series 內新增多個 series ,然後每個對應不同的欄位 (yField or xField),
因為來自不同欄位,所以可以這樣作,但如果值是來自相同欄位的話,而另一個欄位則儲存分類的類別值,如
不同的 Sales Man就是代表一條線,那要怎麼作呢,這邊有範例可以參考,使用XML方式,而程式碼的部份資料來源是使用 ArrayCollection,應該就可以達成其功能了。
Dynamic Create Series By XML Data Source
coding
try {
var wholist:Array = new Array();
var property:String ;
//partXRData is an arraycollection
for(var i:int =0; i property = partXRData.getItemAt(i).USER_NAME as String;
if (wholist[property] == null){
wholist[property] = new ArrayCollection();
}
(wholist[property] as ArrayCollection).addItem(partXRData.getItemAt(i));
}
var currentSeries:Array = new Array();
var count1:int = 0;
var localSeries:LineSeries = null;
for each (var ac1:ArrayCollection in wholist) {
// Create the new series and set its properties.
localSeries = new LineSeries();
localSeries.dataProvider = ac1;
localSeries.yField = "AVERAGE1";
localSeries.xField = "VALUE_SN";
// Set values that show up in dataTips and Legend.
localSeries.displayName = ac1.getItemAt(0).USER_NAME;
// Back up the current series on the chart.
// Add the new series to the current Array of series.
currentSeries.push(localSeries);
}
// Add the new Array of series to the chart.
avgChart1.series = currentSeries;
}catch(error:Error) {
}
因為來自不同欄位,所以可以這樣作,但如果值是來自相同欄位的話,而另一個欄位則儲存分類的類別值,如
Sales Man | Date | Amount |
Sales A | 2010/01/01 | 100 |
Sales B | 2010/01/01 | 200 |
Dynamic Create Series By XML Data Source
coding
try {
var wholist:Array = new Array();
var property:String ;
//partXRData is an arraycollection
for(var i:int =0; i
if (wholist[property] == null){
wholist[property] = new ArrayCollection();
}
(wholist[property] as ArrayCollection).addItem(partXRData.getItemAt(i));
}
var currentSeries:Array = new Array();
var count1:int = 0;
var localSeries:LineSeries = null;
for each (var ac1:ArrayCollection in wholist) {
// Create the new series and set its properties.
localSeries = new LineSeries();
localSeries.dataProvider = ac1;
localSeries.yField = "AVERAGE1";
localSeries.xField = "VALUE_SN";
// Set values that show up in dataTips and Legend.
localSeries.displayName = ac1.getItemAt(0).USER_NAME;
// Back up the current series on the chart.
// Add the new series to the current Array of series.
currentSeries.push(localSeries);
}
// Add the new Array of series to the chart.
avgChart1.series = currentSeries;
}catch(error:Error) {
}
訂閱:
文章 (Atom)