Getting data into the chart
The functions layer will contain the LoadChartData function. This function will load the XML data into the chart component. The chart will be referenced by using the instance name MyChart.
The first thing to do is create the function on the functions layer and set up a reference for the chart node in the XML document.
function LoadChartData() {
var BaseNode = thisXML.childNodes[0];
}
We will use the BaseNode to reference other nodes within the XML document. The chart data is contained in the child nodes of the base node. These are the chartItem nodes.
The following code loads the label and values for each chart item into an array and then adds them to the ChartData data source. I chose the names DataLabel and DataValue for the fieldnames in the data source.
//set up arrays
var ArrLabel = new Array();
var ArrValue = new Array();
var ThisNode;
//create datasource
var ChartData = new DataProviderClass();
//get Chart Data
for (var i=0; i < BaseNode.childNodes.length; i++) {
ThisNode = BaseNode.childNodes[i];
ArrLabel[i] = ThisNode.attributes["ChartLabel"];
ArrValue[i] = ThisNode.attributes["ChartValue"];
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 XML file.
The complete code for the functions frame is on the next page.
| » Level Intermediate |
|
Added: 2002-08-07 Rating: 7.79 Votes: 33 |
| » Author |
| Applications Developer Marconi Australia |
| » Download |
| Download the files used in this tutorial. |
| Download (120 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!