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 –>

19 Responses to “Using dynamic data with charts”

  1. Ramesh Says:

    Can you post some asp examples for doing the same

  2. Ali Says:

    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

  3. Srujan Says:

    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

  4. Joe Stone Says:

    Why do you hide the usefull PHP Exemples from the amline_data.php ?

    Maybe some People can guess the code !?

  5. Stef Says:

    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!

  6. admin Says:

    Sorry, here is the source:

    http://www.amcharts.com/line/examples/dynamic_data/amline/amline_data.php_

  7. Mark Lewis Says:

    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

  8. Mark Lewis Says:

    sorry, that $PType is defined as
    $PType = ‘http://62.233.100.208/xmlreport/AMcharts/Registrations2.xml?Producttype=’.$_REQUEST[’Producttype’];

  9. Guido Says:

    How can i graph this :
    http://uk.old.finance.yahoo.com/d/quotes.csv?s=LAN.L&f=sohgl&e=.csv

    Thanx :-)

  10. Steven Says:

    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.

  11. Steven Says:

    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!

  12. Border Says:

    Can you post some Django examples for dynamic data.

    Thanks.

  13. Alec Says:

    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.

  14. Alec Says:

    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”);

  15. joko Says:

    how do you do it in asp. can you show me example of that??? thank you

  16. Harshad Riswadkar Says:

    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

  17. admin Says:

    please, post your support questions to support forum:
    www.amcharts.com/forum

  18. 10 flash-компонентов для построения графиков для rich web. | Cyrill Says:

    […] классические графики X-Y и многое другое. На сайте и в блоге разработчика приводятся образцы использования и документация. […]

  19. 11 flash-компонентов для построения графиков для rich web | Записки маленького юни Says:

    […] классические графики X-Y и многое другое. На сайте и в блоге разработчика приводятся образцы использования и документация. […]

Leave a Reply

All support questions should be posted to support forums:
AmCharts: http://www.amcharts.com/forum/
AmMap: http://www.ammap.com/forum/


two girls one cup
two girls one cup 2 girls 1 cup video 2 girls 1 cup two girls and a cup 2girls and a cup two girls one cup original video two girls one cup 2 girls 1 cup two girls and a cup 2girls and a cup two girls one cup original video two girls one cup 2 girls 1 cup two girls and a cup all about 2 girls one cup all about 2 gils onw cup all about 2girls one cup all about two girls one cup two girls one cup all about two girls 1 cup