I’m new to Flex. I’ve been graphing multiple series in a line chart where all of these series are the same length. Now I need to plot new data and each series has a different length from each other. The question is how to modify the following code to do this.
The initApp() function is called at the start of the program, and it calls function genData() to generate the dataSet used for plotting in the LineChart.
public function initApp():void {
// Initialize data provider array.
dataSet = new ArrayCollection(genData());
}
public function genData():Array {
var result:Array = [];
include "Data_File.as"; // load myarray<1|2|3|4> example data
for (var ii:int = 0; ii < myarray1.length; ii++) {
var localVals:Object = {
x1:myarray1[ii],
y1:myarray2[ii],
x2:myarray3[ii],
y2:myarray4[ii]
};
result.push(localVals); // Push new object onto the data array.
}
return result;
}
The variable “dataSet” is used as follows to plot multiple series.
<mx:LineChart id="myChart" dataProvider="{dataSet}">
<mx:series>
<mx:LineSeries id="series1" xField="x1" yField="y2"/>
<mx:LineSeries id="series2" xField="x2" yField="y2"/>
</mx:series>
</mx:LineChart>
Can someone recommend how to place array1, array2, array3, and array4 into x1, y1, x2, y2 (respectively) when the length of array1 and array2 do not equal that of array3 and array4? Or, equivalent outcome.
I’m assuming everything has to come in through dataSet, but I wonder if it’s possible to simply reference array1 (etc.) directly from <mx:LineChart ...> or <mx:LineSeries ...> somehow, to avoid wasting memory on an unnecessary array (e.g. dataSet).
How about setting the index to a value if the array is not long enough?