First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
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: S.Saipriya
» Title: Flash Fire Effect
» Description: This tutorial explains about how to create Fire Effect in Flash of Actionscript 2.0.I hope this tutorial helps you!
Featured Sound Loops
Image for equalize

Audio Player

» Author: Aidan Crouzet-Pascal
» Title: Falling Star
» Description: This loop is a cool sounding, E minor loop.
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: Brandan Paulin
» Description: Epic sounding loop with Brass, Percussion, Strings and Winds. This is actually part of a Loop Pack called the Coming where you can download the rest of the loops that go with it FREE from my website.