On Monday, May 11, 2015 at 6:27:34 PM UTC+5:30, Gaurav Mohla wrote:
>
> I have a chart compliant json 
> {"cols":[{"label":"name","type":"string"},{"label":"count","type":"number"}],"rows":[{"c":[{"v":"Name"},{"v":1}]},{"c":[{"v":"Name1"},{"v":2}]},{"c":[{"v":"Name2"},{"v":3}]},{"c":[{"v":"Name4"},{"v":1}]}]}
>  
> which I want to display as Google Chart on my sceen. using ajax call I am 
> able to form the foll code:
>
> <script>
> $(document).ready(function(){
>     google.load('visualization', '1', {
>         packages: ['corechart']
>     });
>
>
>     function drawBasic(d) {
>       var data = new google.visualization.DataTable(d);
>       var options = {
>          title: 'Sample Data',
>          hAxis: {
>             title: 'Name'
>          },
>          vAxis: {
>             title: 'Count'
>          },
>          width: 400,
>          height: 240
>       };
>
>
>       var chart = new google.visualization.ColumnChart(document.
> getElementById('chart_div'));
>       chart.draw(data, options);
>     }
>
>
>     $.ajax({
>         url : "Serv",
>         dataType: 'json',
>          contentType: 'application/json',
>         success : function(result) {
>           google.setOnLoadCallback(drawBasic(JSON.stringify(result)));
>         },
>         complete: function(){
>            // whatever..
>         }
>     });
>
>
>  });
> </script>
> but still I am unable to display the data.
>
> jsbin link: http://jsbin.com/hofaqidape/2/watch?html,js,output 
> <http://jsbin.com/hofaqidape/2/watch?html,js,output> . This is what I am 
> trying to do dynamically. could somebody help me.
>
> Thanks :)
>

I am able to generate the chart after removing $(document).ready() and 
using the technique that you pointed out but without using ready function 
my $.ajax() does not work upon selecting a value from drop down which I 
need for dynamic data generation. So i need to have these two techniques 
collaborating. Any way out?
The script I am using right now:

   
google.load('visualization', '1', {
        packages: ['corechart']
    });


    function drawBasic(d) {
      var data = new google.visualization.DataTable(d);
      var options = {
         title: 'Sample Data',
         hAxis: {
            title: 'Name'
         },
         vAxis: {
            title: 'Count'
         },
         width: 400,
         height: 240
      };


      var chart = new google.visualization.ColumnChart(document.
getElementById('chart_div'));
      chart.draw(data, options);
    }  
    
$("#dd").change(function(){
     $.ajax({
        url : "Serv",
        data: {dd1:$(this).val()};
        dataType: 'json',
         contentType: 'application/json',
        success : function(result) {
        alert(result);
          google.setOnLoadCallback(drawBasic(result));
        },
        complete: function(){
           // whatever..
        }
    }); 
    });

    where 'dd' is the id of drop down after which I am sending its value to 
servlet for further processing but this doesnt work without 
document.ready().

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to