pimlinders Report post Posted August 14, 2009 I'm trying to figure out how to have my charts updated every minute without the user having to do anything (such as clicking on a button/chart), Is this possible to do? My data is stored in a mysql database and I based my php code off of the "Combining FusionCharts, PHP & JavaScript (dataURL) method". Share this post Link to post Share on other sites
Guest Rajroop Report post Posted August 17, 2009 Hello, You can achieve your requirements by using the setInterval function of JavaScript. The setInterval method is available on window objects. It is used to add a delay to a function (usually one that is going to be executed multiple times). This is not a reserved word so you can declare your own variable or function called setInterval but if you do then you will not be able to use the method. Ref: http://www.switchonthecode.com/tutorials/javascript-tutorial-using-setinterval-and-settimeout For example: <script type="text/javascript"> var myChart = new FusionCharts("Column2D.swf", "myChartId", "500", "400", "0", "1"); myChart.setDataURL("Data.xml"); myChart.render("chartdiv"); var intrv; function FC_Rendered(DOMId){ intrv = window.setInterval(function(){updateChart();} , 1000); } I hope this helps. Share this post Link to post Share on other sites
pimlinders Report post Posted August 17, 2009 I'm generating my xml with PHP, I guess I should create a php function that gets called on load and call that function using setInterval. Does any one know of a way to do this, I assume this is done with ajax but I'm a little confused on how I could refresh only the chart and not the entire page. Again thanks for the help. Share this post Link to post Share on other sites
Guest Rajroop Report post Posted August 17, 2009 Hello, Could you see the attached file and see if it helps? refresh.zip Share this post Link to post Share on other sites
pimlinders Report post Posted August 17, 2009 Rajroop (8/17/2009)Hello, Could you see the attached file and see if it helps? thanks Rajroop, i'll look over this and let you know. Share this post Link to post Share on other sites
FusionCharts Support Report post Posted August 17, 2009 Hi, If you are using FusionCharts v3 you can do it just using setInterval without any 3rd party AJAX or native AJAX code. FusionCharts v3 has inbuilt AJAX support. Only you would need to specify the php page's URL which is generating the XML to charts's setDataURL() function. Thats it! so, now your updateCharts() function will have a changed line : getChartFromId('myChartid').setDataXML(YourPHPScriptURL); Here, instead of 'myChartid' place your chart ID and pass your PHP URL. The chart will load the XML form the PHP file and would redraw. No page refresh! Share this post Link to post Share on other sites
pimlinders Report post Posted August 18, 2009 (edited) I ended up creating a php file that generates xml files and took out the php code that generated the initial xml file on the main page and having javascript generate the chart, everything works now, thanks for the help! Edited August 18, 2009 by Guest Share this post Link to post Share on other sites
Guest Rajroop Report post Posted August 19, 2009 Great! Happy FusionCharting. Share this post Link to post Share on other sites