If you write it to get data from an AJAX query to begin with (ie, get rid the the PHP the adds the data to the script and fetch directly from AJAX), then you can call the draw function from the success handler of the AJAX call. When you need to update the data, run the AJAX again.
On Friday, May 25, 2012 4:33:32 AM UTC-4, somekey wrote: > > Hi, I am new to the Visualization API. > I am writing a simple column chart to display the "weight" data for a > user, here is what my code looks like: > > <?php > //.... some php code to get data from database > //...then data is formatted and put in a string called $chart_data > $chart_data ='['2012-01-02', 58.6], ['2012-01-03', 60.6], > ['2012-01-04', 61.6], ['2012-01-05', 63.6]'; > ?> > > <html><head> > <script type="text/javascript" src="https://www.google.com/jsapi"></ > script> > <script type="text/javascript"> > google.load('visualization', '1.0', {'packages':['corechart']}); > google.setOnLoadCallback(drawChart); > > function drawChart() { > var data = new google.visualization.DataTable(); > data.addColumn('string', 'Date'); > data.addColumn('number', 'Kg'); > data.addRows([ > <?php echo $chart_data; ?> > ]); > var options = {'title':'Body Weight','width':750,'height': > 300}; > var chart = new > google.visualization.LineChart(document.getElementById('chart')); > chart.draw(data, options); > } > </script> > </head> > <body><div id="chart"></div></body> > </html> > > I have some AJAX code to get a new set of data, but the question is : > How to update the chart data after I get it updated from AJAX > response? > > what I am thinking is to write another drawChart function which takes > a parameter and pass the new data to it. > I am not sure if this is the right direction, please help, thanks a > lot! > -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/8n05aN1WymUJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
