Sign in to follow this  
oach

Prototype ajax update chart

Recommended Posts

Hi All,

 

 

 

There is a chart on a page that is created while the page loads via php. This works w/out a problem. I am using prototype attached to specific links on the page that I want to be able to change the chart on the page. I have tried to search the forums but haven't found a ton on the topic and I don't quite understand how to update.

 

 

 

Here is some code

 


// this works fine



var obj_fs = new FusionCharts('<?php echo base_url(); ?>javascript/fusioncharts_v3/Charts/Line.swf', 'fc_1', '940', '200');

obj_fs.setDataXML('<?php echo $data; ?>');

obj_fs.render('ga_largeChart');



// ajax call

new Ajax.Request('../ga_getGraph/pageviews', {asynchronous: true, evalScripts: true, method: 'get', onComplete: function(response) {$('ga_largeChart').update(response.responseText);}}); return false;

 

Response text is similar to the js above (don't know another way of doing it - that's why I am asking the question.

 

 

 

Thank you for your time and help,

 

oach

Share this post


Link to post
Share on other sites

Been working on this and found some information in the documentation. So this is what my code looks like:

 




var obj_fc = new FusionCharts('<?php echo base_url(); ?>javascript/fusioncharts_v3/Charts/Line.swf', 'fc_1', '940', '200', '0', '0');

obj_fc.setDataURL('xml/fc.xml');

obj_fc.render('ga_largeChart');



// and

function processAJAX(url) {

var obj_chart = getChartFromId('fc_1');

url += '?nocache=' + new Date().valueOf();

obj_chart.setDataURL(url);

}



// ajax call

new Ajax.Request('ga_getGraph/pageviews', {asynchronous: true, evalScripts: true, evalJS: true, method: 'get', onComplete: function(response) {processAJAX(response.responseText);}}); return false;

 

I know that the url variable has the correct url (alert) and I have checked the xml file, which gets updated BUT the chart does not get updated. No errors on the page either.

 

 

 

Any ideas?

 

 

 

Thank you,

 

oach

Share this post


Link to post
Share on other sites
Guest Rajroop

Hello,

 

 

 

Could you please try with registerWithJS option on?

 

 

 

You have used:

 

 

 

ar obj_fc = new FusionCharts('javascript/fusioncharts_v3/Charts/Line.swf', 'fc_1', '940', '200', '0', '0');

 

 

 

This should be:

 

 

 

ar obj_fc = new FusionCharts('javascript/fusioncharts_v3/Charts/Line.swf', 'fc_1', '940', '200', '0', '1');

 

 

 

Hope this helps. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this