Using dynamic data with charts
I 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 –>
May 11th, 2007 at 1:48 pm
Can you post some asp examples for doing the same
August 1st, 2007 at 7:11 pm
Can you please show all the source codes for the two pages: amline_data.php and index.php.
And if possible, can you show how to create a column chart?
thanx
August 9th, 2007 at 6:26 pm
How can I read data from an Oracle database and show it in the graphs format, can you please help me how to do it?
Please let me know if you need any information
August 28th, 2007 at 10:24 am
Why do you hide the usefull PHP Exemples from the amline_data.php ?
Maybe some People can guess the code !?
August 29th, 2007 at 1:51 pm
Hi, yep, I agree to what Joe said: Can’t you publish the content of amline_data.php? I think that is a pretty important part of the whole dynamic stuff… Would be useful to see how you achieve that!
Thanks for any hints!
August 30th, 2007 at 6:11 am
Sorry, here is the source:
http://www.amcharts.com/line/examples/dynamic_data/amline/amline_data.php_
September 11th, 2007 at 8:16 pm
Hi Antanas,
Love this application! But I’m not a coder…I have applied a slightly different approach and use MSSQL templates to generate the XML dynamically which also allows variables to be set and let’s the SQL template do the hard work.
Only problem is that currently I cannot reference the XML directly (http) in the line
so.addVariable(”data_file” …
since I believe the path is set by so.addVariable(”path”… for flash.
I am currently doing an automated (each 15min) HTTP download from the MSSQL virtual directory to a subfolder which can be accessed by the AMcharts code… This works just great….
However I want more! I wanted to be able to make use of the useful parameter capability within MSSQL templates to filter the data ‘on the fly’ using the URL feature within AMChart attributes…. the cleanest way to achieve this would be to enable me to do something like this…
Set the URL attribute in the XML to link to
…/xml_reports/am_reports.php?Producttype=Now
then set in my PHP page displaying the chart…
….
so.addVariable(”path”, “report_data/”);
so.addVariable(”settings_file”, escape(”report_data/Regs_by_keywd_by_wk/amcolumn_settings.xml”));
so.addVariable(”data_file”, escape(”$PType”));
But of course this does not work… Any thoughts / suggestions ?
Kind regards,
Mark Lewis
London, England
September 11th, 2007 at 8:20 pm
sorry, that $PType is defined as
$PType = ‘http://62.233.100.208/xmlreport/AMcharts/Registrations2.xml?Producttype=’.$_REQUEST[’Producttype’];
September 24th, 2007 at 11:14 pm
How can i graph this :
http://uk.old.finance.yahoo.com/d/quotes.csv?s=LAN.L&f=sohgl&e=.csv
Thanx :-)
October 11th, 2007 at 9:02 am
I need the code of the example!!!!!!!
I even don’t know how to set the “chart_data” in the amline script, so the code of the example would be very helpful.
October 11th, 2007 at 9:13 am
The same as the No.8 example of Line & Area chart which can reload the data every x seconds, I need the code too. Please tell where can I get the code , or send it to my mail.Thank you!
November 12th, 2007 at 7:03 am
Can you post some Django examples for dynamic data.
Thanks.
December 6th, 2007 at 3:12 am
Excellent charts! Congratulations on this product.
I am creating dynamic charts by putting the HTML code that loads the flash object in my HTML templates like this:
//
Then a php script pulls the data from the database and loads it into the template using the {chart_data} and {chart_settings} tags like this:
$chart_data = get_data_from_db();
$chart_data = implode(’\n’, $chart_data);
echo parse_template(HTML_REPORT_CHART, array(
height => ‘1000′
,chart_data => $chart_data
,chart_settings => $settings
));
This solution is obvious but thought I would post it for those who want to cleanly separate data, logic, and presentation layers.
December 6th, 2007 at 3:13 am
Oops…. here is the text between the script tags that goes into the HTML template:
var so = new SWFObject(”flash/amcolumn/amcolumn.swf”, “amcolumn”, “100%”, “{height}”, “8″, “#ffffff”);
so.addVariable(”chart_data”, “{chart_data}”);
so.addVariable(”chart_settings”, “{chart_settings}”);
so.addVariable(”preloader_color”, “#999999″);
so.write(”flashcontent”);
December 17th, 2007 at 9:19 am
how do you do it in asp. can you show me example of that??? thank you
December 27th, 2007 at 1:22 pm
Hi,
How can I do this in an asp.net page? I am using ASP.NET 2.0 and trying to show data of each investor in pie chart. I have a grid which displays data of all investor and when clicked on each investor the pie chart is loaded.
The problem is that pie chart does not refresh/reloads to show data of another user. It displays the data correctly only for the first time.
Can any one help me on this?
Thanks,
Harshad
December 27th, 2007 at 1:52 pm
please, post your support questions to support forum:
www.amcharts.com/forum
January 25th, 2008 at 12:53 pm
[…] классические графики X-Y и многое другое. На сайте и в блоге разработчика приводятся образцы использования и документация. […]
March 10th, 2008 at 11:28 am
[…] классические графики X-Y и многое другое. На сайте и в блоге разработчика приводятся образцы использования и документация. […]