chart tool wont load after successful submit event

69 views
Skip to first unread message

roy782

unread,
Apr 30, 2012, 8:17:27 AM4/30/12
to google-visua...@googlegroups.com
Hello,
I'm trying to draw a pie chart after a form submit event
for some reason the page becomes bllank (after google.load)
and nothing is working. i tried to debug several times without success

can anyone please help me?
Thanks!
Roy

the code:
$(function(){
    $('#searchForm').submit(function(event){
        event.preventDefault();
        $('#MotifSearch').animate({
            left: '25%',
            width: '50%',
            height: '75%'
        }, 1500);
        $('#motifGraphTitle').animate({
            left: '25%'
        }, 1500);
        var formData = $(this).serialize();
        var empty = '';
        var jqxhr = $.post('formHandle.php', formData, loadGraph);
        
    
        jqxhr.success(function(){ 
            $.getJSON('loadTaxo.php', empty, loadTaxo).complete(function() { 
                google.load('visualization', '1.0', {
                    'packages':['corechart']
                    });
                google.setOnLoadCallback(drawChart);
                
            });
            
        });
        
        $('#taxoLabel').show(500);
    
        
      
        // Set a callback to run when the Google Visualization API is loaded.
        
        return false;
    });//end submit
    
});*/

asgallant

unread,
Apr 30, 2012, 12:30:33 PM4/30/12
to google-visua...@googlegroups.com
The google loader doesn't play nice with other AJAX (or, perhaps, vice-versa), so you should load the API first, and put your AJAX inside the callback function.

roy782

unread,
May 4, 2012, 5:29:09 AM5/4/12
to google-visua...@googlegroups.com
Thanks for the replay,
Is there a way to make sure that the callback function will be loaded only after i return from the ajax calls
becuase from the ajax calls i'm getting all the data for the chart tools.

But anyhow i will try to work around it if it's not possible
Thanks
Roy

asgallant

unread,
May 4, 2012, 9:16:10 AM5/4/12
to google-visua...@googlegroups.com
You just need to draw the chart in the success handler for the AJAX call:

google.load('visualization''1.0'{'packages'['corechart']});
google.setOnLoadCallback(init);

function init ({

    $('#searchForm').submit(function(event){
        event.preventDefault();
        $('#MotifSearch').animate({
            left'25%',
            width'50%',
            height'75%'
        }1500);
        $('#motifGraphTitle').animate({
            left'25%'
        }1500);
        var formData $(this).serialize();
        var empty '';
        var jqxhr $.post('formHandle.php'formDataloadGraph);
        
    
        jqxhr.success(function(){
            // you need to grab the returned data if you want to use it to draw the chart

            $.getJSON('loadTaxo.php'emptyloadTaxo).complete(function({
                drawChart();

            });
        });
        
        $('#taxoLabel').show(500);
        
Reply all
Reply to author
Forward
0 new messages