First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Sas Jacobs | Website: http://www.flashkit.com

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]});
}

Note: You don't have to load the chart labels and values into an array first, but it might be useful if you're going to use the information in some other way.

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
(10 being the highest)
» Author
Applications Developer Marconi Australia
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.