jquery - load google charts through an ajax call -


i'm trying call google chart after clicking on link. function looks like:

function getgraphdata(id) {      var ajax_url = '<?=url?>ajaxlibrary/get-graph-data';      $.ajax({         type: 'post',         url: ajax_url,         datatype: 'html',         data: ({             id : id       }),         cache: false,         success: function(data) {             $('a').removeclass("selected");             $('#link_'+id).addclass("selected");             alert(data);          },     }); } 

so i'm trying achieve here load different graph different like, lets have politics charts, sports charts etc. don't know put google api code though, because seems it's not working...

edit: edited function this:

  $.ajax({          type: "post",          datatype: "html",          data: {id: id},          url: '<?=url?>' + 'ajaxlibrary/get-charts',          success: function(datas) {             console.log(datas);             var data = google.visualization.arraytodatatable([                     datas             ]);              var options = {                 title: 'my daily activities'             };              var chart = new google.visualization.piechart(document.getelementbyid('chart_div'));             chart.draw(data, options);          }     });  

but i'm having issues sending data stream ajax php file:

echo '[\'task\', \'hours per day\'],             [\'work\',     10],             [\'shit\',     50],             [\'loop\',     25],             [\'poop\',     15]'; 

the response not valid 2d array. if put values in javascript file manually, works, issue somewhere in response.

you can load google charts ajax call using below code.

$.ajax({   url: 'https://www.google.com/jsapi?callback',   cache: true,   datatype: 'script',   success: function(){     google.load('visualization', '1', {packages:['corechart'], 'callback' : function()       {              $.ajax({                  type: "post",                  datatype: "json",                  data: {id: youridhere},                  url: '<?=url?>' + 'ajaxlibrary/get-charts',                  success: function(jsondata) {                     var data = google.visualization.arraytodatatable(jsondata);                      var options = {title: 'my daily activities'};                      var chart = new google.visualization.piechart(document.getelementbyid('chart_div'));                     chart.draw(data, options);                  }             });             ]);        }     });     return true;   } }); 

you can load other chart types instead of corechart using google api.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -