First time here? First time here? Newsletter Signup Newsletter
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.


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!


  • 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: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
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: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.