Getting data into the chart
The third frame will contain all the actionscript for loading the data into the chart component.We will reference the chart by using the instance name MyChart.
The data and labels for the chart are contained within a comma separated list so the first thing we need to do is to separate the values into arrays as shown below.
//create arrays containing variables
var ArrLabel = loading.ChartLabels.split(",");
var ArrValue = loading.ChartValues.split(",");
Then create a data source for the chart that will contain these arrays.
var ChartData = new DataProviderClass();
Loop through the ArrLabel and ArrValue arrays and add their values
to the ChartData data source. I chose the names DataLabel and DataValue
for the fieldnames.
for (var i=0; i < ArrLabel.length; i++) {
ChartData.addItem({DataLabel:ArrLabel[i], DataValue:ArrValue[i]});
}
The next step is to link the datasource to the MyChart object and indicate
which fields contain the labels and values.
MyChart.setDataProvider(ChartData);
MyChart.setLabelSource("DataLabel");
MyChart.setValueSource("DataValue");
Test the movie and you should see a chart populated with the values from your external file.
The complete code for the third frame is on the next page.
| » Level Intermediate |
|
Added: 2002-07-14 Rating: 8 Votes: 27 |
| » Author |
| Applications Developer Marconi Australia |
| » Download |
| Download the files used in this tutorial. |
| Download (107 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!