2007-05-03 Using dynamic data with chartsI received some enquiries and understood, that I need to give some more explanations about using dynamic data with chart products. When using dynamic data you don't need to create and save xml or csv files on your server. Your data file, (which can be php or asp or any other script) should output xml or csv formatted text. This example is made with php, but you can do it with other languages as well: http://extra.amcharts.com/line/dynamic_data/index.php?title0=Income&title1=Expenses Try to change "Income" and "Expenses" in url to some other text and you'll see that text in the legend changes too. Let's see what we have in the index.php file: so.addVariable("data_file", escape("amline/amline_data.php?title0=<? echo ($_GET['title0']); ?>&title1=<? echo ($_GET['title1']); ?>"));
As you can see I set data file name as amline_data.php file and attached two variables to it - title0 and title1. This php code:
<?php echo ($_GET["title0"]); ?>
just gets title0 from your url. You can pass any variables in this way.
Flash script receives data url and then loads data accessing this url with all variables you passed. So data file can generate result according to parameters. Of course data file can generate dynamic result even if you don't pass any variables, all depends on your needs. Now check this url and view source of the file - this xml was generated dynamically by php script. In this case I just generated some random data. Usually you will not do this, instead you might want to get data from database, another xml file or anywhere else.
This works with all charts.
Source code of amline_data.php file
Full source of index.php:
<!-- saved from url=(0013)about:internet -->
<!-- amline script-->
<script type="text/javascript" src="amline/swfobject.js"></script>
<div id="flashcontent">
<strong>You need to upgrade your Flash Player</strong>
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("amline/amline.swf", "amline", "520", "400", "8", "#FFFFFF");
so.addVariable("path", "amline/");
so.addVariable("settings_file", escape("amline/amline_settings.xml"));
so.addVariable("data_file", escape("amline/amline_data.php?title0=<? echo ($_GET['title0']); ?>&title1=<? echo ($_GET['title1']); ?>"));
so.addVariable("preloader_color", "#999999");
so.write("flashcontent");
// ]]>
</script>
<!-- end of amline script -->
<< Previous | Next >>
|